Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql触发器创建失败_Mysql_Triggers_Creation - Fatal编程技术网

Mysql触发器创建失败

Mysql触发器创建失败,mysql,triggers,creation,Mysql,Triggers,Creation,我对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=

我对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 ||
我得到以下错误

第177行出现错误1064 42000:SQL语法有错误; 检查与您的MariaDB服务器版本对应的手册以了解 使用near'-将旧项插入 根据第7行的项目ty'对应的新表格


我仔细查看了声明,但它们对我来说似乎很好。

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

删除注释-。。。从您的触发器中,我在前面尝试过这个,然后在第177行得到错误1064 42000:您的SQL语法中有一个错误;检查与您的MariaDB服务器版本相对应的手册,了解可在第12行的“SET COUNT=SELECT count1 FROM tracking_item WHERE tracking_item_valu”附近使用的正确语法,其中tracking_item_valu发现错误a,然后