创建触发器的问题

时间:2010-05-05 04:15:41

标签: mysql sql triggers mysql-error-1064

我在创建触发器时遇到问题,我不确定为什么会出错。请你帮助我。

我已经写了一个下面提到的触发器,它在尝试执行触发器时给了我这个错误...

  

1064 - 您的SQL语法出错;检查与您的MySQL服务器版本对应的手册,以便在'DECLARE store_itemid INTEGER附近使用正确的语法; store_hostid INTEGER; store_desc VARCHAR(255);'在第4行

代码:

mysql> delimiter //
   CREATE TRIGGER init_trigger 
   AFTER INSERT ON test_trigger
   FOR EACH ROW
   DECLARE 
     store_itemid INT;
     store_hostid INT;
     store_desc VARCHAR(255);
     store_key VARCHAR(255);
     store_lastvalue VARCHAR(255);
     store_lastclock VARCHAR(255);
     store_preval INT;
     store_status INT;
   BEGIN

     SELECT itemid into store_itemid,
            hostid into store_hostid,
            description into store_desc,
            key_ into store_key,
            lastvalue into store_lastvalue,
            lastclock into store_lastclock,
            prevvalue into store_preval,
            status into store_status 
       FROM test_triggers 
      WHERE lastvalue > 80;

     IF store_lastvalue > 80 THEN
        INSERT INTO test_triggers1 
          (itemid,hostid,description,key,lastvalue,lastclock,prevvalue,status) 
        VALUES
          (store_itemid,store_hostid,store_desc,store_key,store_lastvalue,store_lastclock,store_preval,store_status);

     END IF;
   END;
   // 

1 个答案:

答案 0 :(得分:0)

你必须在“ROW”之后添加“BEGIN”