创建触发器时出现问题
我在创建触发器时遇到问题,我不确定为什么会出错。您能帮助我吗?
我写了一个下面提到的触发器,它在尝试执行触发器时给了我这个错误......
1064 - 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在 'DECLARE store_itemid INTEGER; 附近使用的正确语法。 store_hostid 整数; 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;
//
I am facing a problem in creating a trigger and i am not sure why this is erroring out.can you please help me.
I have written a trigger mentioned below and it gives me this error upon trying to execute the trigger ...
1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DECLARE store_itemid INTEGER; store_hostid INTEGER; store_desc VARCHAR(255);' at line 4
Code:
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;
//
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你必须在“ROW”之后添加“BEGIN”
U must add "BEGIN" after "ROW"