我正在尝试触发 mysql 事件来对现实世界的事件使用react。
设置: 我创建了一个持久事件,并尝试从存储过程重新安排它。
在存储过程中,我计算时间戳并将其存储在 l_EndDateTime 中。
ALTER EVENT MyEvent
ON SCHEDULE EVERY 4 HOUR STARTS l_EndDateTime
ON COMPLETION PRESERVE;
这会给出错误 1054,表明它不是有效的列。
阅读此评论后:
The ON SCHEDULE clause may use expressions involving built-in MySQL functions and user variables to obtain any of the timestamp or interval values which it contains. You cannot use stored routines or user-defined functions in such expressions, and you cannot use any table references; however, you can use SELECT FROM DUAL. This is true for both ALTER EVENT and CREATE EVENT statements. Beginning with MySQL 5.1.13, references to stored routines, user-defined functions, and tables in such cases are specifically not permitted, and fail with an error (see Bug #22830).
我尝试过这个:
ALTER EVENT MyEvent
ON SCHEDULE EVERY 4 HOUR STARTS (SELECT l_EndDateTime FROM DUAL)
ON COMPLETION PRESERVE;
这会产生不同的错误。
有什么建议吗?
最佳答案
您需要使用用户变量而不是存储过程级别变量
SET @l_EndDateTime = NOW();
ALTER EVENT MyEvent
ON SCHEDULE EVERY 4 HOUR STARTS @l_EndDateTime
ON COMPLETION PRESERVE;
这样就可以了。
关于MySQL:从存储过程重新安排事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17302988/