gpt4 book ai didi

Mysql触发器创建失败

转载 作者:行者123 更新时间:2023-11-30 22:55:32 24 4
gpt4 key购买 nike

我在 mysql 中使用以下触发器有问题

CREATE TRIGGER item_fw_insert_trigger 
BEFORE INSERT ON item
FOR EACH ROW
BEGIN
DECLARE ITEM_ID BIGINT;
DECLARE COUNT INT;
--insert an old item into the corresponding new table depending on the item type
IF NEW.type=2 THEN
INSERT INTO sms_item (sms_item_value,phone_number,counter,client_ip) VALUES (NEW.item,NEW.value,NEW.counter,NEW.client_ip);
ELSEIF NEW.type=3 THEN
INSERT INTO email_item (email_item_value,email,counter,client_ip) VALUES (NEW.item,NEW.value,NEW.counter,NEW.client_ip);
ELSEIF NEW.type=4 OR NEW.type=5 OR NEW.type=6
SET COUNT =(SELECT count(1) FROM tracking_item WHERE tracking_item_value=NEW.item);
IF COUNT=0 THEN
INSERT INTO tracking_item (tracking_tocken_value,first_name,last_name,scn,counter) VALUES
(NEW.item,'','','',0);
END IF;
IF NEW.type=4 THEN
UPDATE tracking_item SET first_name=NEW.value WHERE tracking_item_value=NEW.item;
ELSEIF NEW.type=5 THEN
UPDATE tracking_item SET last_name=NEW.value WHERE tracking_item_value=NEW.item;
ELSEIF NEW.type=6 THEN
UPDATE tracking_item SET scn=NEW.value WHERE tracking_item_value=NEW.item;
END IF;
ELSEIF NEW.type=7 THEN
-- to delete the phonenumbers for a tracking item we ned the id of the tracking item to have the foreign key
SET ITEM_ID = (SELECT tracking_item_id FROM tracking_item WHERE tracking_item_value=NEW.item);
INSERT INTO tracking_item_phonenumbers (tracking_item_id,phone_numbers) VALUES
(ITEM_ID,NEW.value);
END IF;
-- no else needes since all item types are covered
END ||

出现以下错误

ERROR 1064 (42000) at line 177: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '--insert an old item into the corresponding new table depending on the item ty' at line 7

我仔细查看了声明,但我觉得它们还不错。

最佳答案

从您的代码中删除所有 3 条注释,因为它们在语法上是错误的。

关于Mysql触发器创建失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26542949/

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