MySQL:从存储过程重新安排事件?

标签 mysql events stored-procedures

我正在尝试触发 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/

相关文章:

php - 如何优化这个简单的 SQL 查询?

php - 插入命令?

php - 与 PHP 时间范围组 id 作斗争 - 开始时间,结束时间。请帮忙!

c# - 使用委托(delegate)在 C# 中实现的观察者模式?

javascript - 文档加载后更改 DOM 元素

c# - C# 中的事件注册范围

mysql - SQL 查找商品级别的折扣

c# - 将带有 FlagsAttribute 的枚举解析为 SqlParameter

php - 如何将数组作为参数传递给mysql中的存储过程?

c# - 启动与 SQL Server 的连接时异常的 SqlException