我想在MYSQL数据库上创建事件。当我运行创建EVENT SCHEDULE的查询时出现此错误:
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 '' at line 8
有线的是,当我在EVENT SCHEDULE中运行查询时,它运行正常而没有任何错误:
这是我正在使用的代码
CREATE DEFINER=`root`@`localhost` EVENT `updateGoals` ON SCHEDULE EVERY 20 MINUTE STARTS '2015-01-01 00:01:00' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN
UPDATE `scores` SET `goals`='0'
WHERE `goals` >'0'
AND
( `PROCESS_DESC` LIKE '%No Goals%'
OR `PROCESS_DESC` LIKE '%NG %'
OR `PROCESS_DESC` LIKE '%Goals 0%');
END$$
答案 0 :(得分:1)
这就是你想要的。这个定界符是令人讨厌和令人困惑的。
DELIMITER $$
CREATE DEFINER=`root`@`localhost`
EVENT `updateGoals`
ON SCHEDULE EVERY 20 MINUTE
STARTS '2015-01-01 00:01:00'
ON COMPLETION NOT PRESERVE ENABLE
DO BEGIN
UPDATE `scores` SET `goals`='0'
WHERE `goals` >'0'
AND
( `PROCESS_DESC` LIKE '%No Goals%'
OR `PROCESS_DESC` LIKE '%NG %'
OR `PROCESS_DESC` LIKE '%Goals 0%');
END$$
你注意到你的活动只会运行一次,对吗?它说ON COMPLETION NOT PRESERVE
。
如果您希望活动保持不变并继续按计划运行,直到DROP
为止,请改为使用ON COMPLETION PRESERVE
。