mysql 触发器delimiter,在创建触发器之前,DELIMITER上的MySQL语法错误

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 submiting the SQL with PHP just like follows, and the error message is:

Invalid query: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DELIMITER $$ CREATE TRIGGER FP_PAGO_AI AFTER INSERT ON FORMA_PGTO FOR EACH R' at line 1

The trigger's code is:

$str[] = "

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

END $$

DELIMITER ;

";

解决方案

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值