MySQL Syntax Error on DELIMITER before CREATE TRIGGER

前端 未结 2 742
死守一世寂寞
死守一世寂寞 2020-12-06 21:40

I\'m trying to rewrite a Trigger that I made with Firebird to a MySql Trigger.

I realy have no idea what could be. If anyone could help me... thanks

I\'m su

相关标签:
2条回答
  • 2020-12-06 21:59

    You don't need DELIMITER $$ at all. That's a mysql client builtin command. Client builtins are not recognized by the SQL parser.

    You can just execute the CREATE TRIGGER statement as a single statement and then you don't need to have a delimiter at the end of the statement. Delimiters are only important in interfaces that support multiple statements (e.g. the mysql client).

    phpMyAdmin also permits multiple statements, so you do need to set the delimiter, but this is done with a user interface control, not the DELIMITER command. See Store procedures in phpMyAdmin

    0 讨论(0)
  • 2020-12-06 22:05

    Execute it directly in PhpAdmin and remove one redundant END

    DELIMITER $$
    
    CREATE TRIGGER FP_PAGO_AU AFTER UPDATE ON FORMA_PGTO
    FOR EACH ROW
    BEGIN
    
        declare rec_count integer;
        declare pg_count integer;
        declare cp_pago integer;
    
        select count(*) from forma_pgto fp where fp.id_cpagar=new.id_cpagar into rec_count;
        select count(pago) from forma_pgto f where f.id_cpagar=new.id_cpagar and f.pago=1 into pg_count;
    
        /* Se todas parcelas estao pagas, entao setar conta paga */
        if (rec_count = pg_count) then
            update cpagar c set c.pago=1 where c.id=new.id_cpagar;
        /* Senao */
        else
            /* Se CPAGAR.PAGO = 1, recebe 0 */
            select cpg.pago from cpagar cpg where cpg.id=new.id_cpagar into cp_pago;
            if (cp_pago = 1) then /* Se cp_pago = 1 */
                update cpagar set pago=0 where id=new.id_cpagar;
            end if;
        end if;
    
    END $$
    
    DELIMITER ;
    
    0 讨论(0)
提交回复
热议问题