2 yuan1990731 yuan1990731 于 2016.03.25 09:31 提问

mysql触发器语法错误问题

CREATE TRIGGER tradecost
AFTER UPDATE ON fentrust
FOR EACH ROW
BEGIN
DECLARE old_account DECIMAL(16,6)
DECLARE old_fid INT(10)
DECLARE trade_account DECIMAL(16,6)

SET old_fid = SELECT old_fid FROM fentrust WHERE old.fEntrustType = 1 AND old.fstatus = 1 AND new.fstatus IN(2,3)
SET trade_account = (SELECT fsuccessamount FROM fentrust WHERE old.fEntrustType = 1 AND old.fstatus = 1 AND new.fstatus IN(2,3))
SET old_account = (SELECT ftotalrmb FROM fwallet WHERE fid = old_fid)

UPDATE fwallet SET ftotalRMB = (old_account-trade_account*0.005)

END

上面的语法有问题 总报错 求助应该怎么写 谢谢

5个回答

yuan1990731
yuan1990731   2016.03.25 09:39

CREATE TRIGGER tradecost
BEFORE UPDATE ON fentrust
FOR EACH ROW
BEGIN
UPDATE fwallet t SET t.ftotalRMB = 1
END

这样也是报错,什么原因呢

yue1123
yue1123   2016.03.25 09:57

报什么错最好说出来。

yuan1990731
yuan1990731   2016.03.25 10:03

DELIMITER $$

CREATE
/*[DEFINER = { user | CURRENT_USER }]*/
TRIGGER v_coin.tradecost AFTER UPDATE
ON v_coin.fentrust
FOR EACH ROW BEGIN

IF old.fEntrustType = 1 AND old.fstatus = 1 AND new.fstatus IN(2,3);

UPDATE fwallet SET ftotalRMB =  ((SELECT ftotalrmb FROM fwallet WHERE fid = old.fus_fid)-old.fsuccessamount*0.005);

END$$

DELIMITER ;
修改之后还是有问题 但是去掉IF语句就能执行了 求指点

yuan1990731
yuan1990731   2016.03.25 10:11

少个 END IF; 解决了

CSDNXIAOD
CSDNXIAOD   2016.03.30 11:23

mysql语法错误
----------------------biu~biu~biu~~~在下问答机器人小D,这是我依靠自己的聪明才智给出的答案,如果不正确,你来咬我啊!

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!