我一直在寻找其他stackoverflow问题,但似乎无法找到我的错。我认为它的语法错误有关。我错在哪个部分?
DELIMITER $$
DROP TRIGGER IF EXISTS keisan
CREATE TRIGGER keisan AFTER INSERT ON profitdb
FOR EACH ROW
BEGIN
DECLARE shinAgentPercent;
SET @shinAgentPercent:=`AgentRisk`-`SubAgentRisk`;
SET NEW.`SubAgentProfit` = `Profit`*(`SubAgentRisk`/100);
SET NEW.`AgentProfit` = `Profit`*(@shinAgentPercent/100);
END;
$$
答案 0 :(得分:0)
您的DROP TRIGGER
之后是否需要结束语句?
DROP TRIGGER IF EXISTS keisan$$
答案 1 :(得分:0)
首先,在drop ...
命令之后需要一个结束语句指示。
DROP TRIGGER IF EXISTS keisan $$
其次,我建议您使用BEFORE INSERT
触发器为表的其他列设置表达式值。
示例:
DELIMITER $$
DROP TRIGGER IF EXISTS keisan $$
CREATE TRIGGER keisan BEFORE INSERT ON profitdb
FOR EACH ROW BEGIN
SET @shinAgentPercent := NEW.AgentRisk - NEW.SubAgentRisk;
SET NEW.SubAgentProfit := NEW.Profit * ( NEW.SubAgentRisk / 100 );
SET NEW.AgentProfit := NEW.Profit * ( @shinAgentPercent / 100 );
END;
$$
-- now reset the delimiter to defaut
DELIMITER ;