gpt4 book ai didi

Mysql触发器: Tried other suggestions but still get Error #1064

转载 作者:行者123 更新时间:2023-11-30 00:07:54 25 4
gpt4 key购买 nike

我一直在这里查看其他 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;
$$

最佳答案

首先,您需要在 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 ;

关于Mysql触发器: Tried other suggestions but still get Error #1064,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24360028/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com