gpt4 book ai didi

mysql - 为什么用复合语句创建EVENT会出现这个错误?

转载 作者:太空宇宙 更新时间:2023-11-03 11:47:12 25 4
gpt4 key购买 nike

来自这个 SO question .我对 DELIMITER 感到困惑。而且我还尝试了如下操作:

CREATE EVENT test
ON SCHEDULE EVERY 2 MINUTE
DO
BEGIN
SELECT 1;
SELECT 2;
END

这让我像提到的问题一样出错:

Error Code: 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 5.

如果我运行以下 sql:

DELIMITER $$
CREATE EVENT test
ON SCHEDULE EVERY 2 MINUTE
DO
BEGIN
SELECT 1;
SELECT 2;
END $$
DELIMITER;

这有效并成功创建了一个新的 EVENT

这两个 sql 之间的唯一区别是最后一个使用了 DELIMITER,所以我的问题是为什么 DELIMITER 在这里起作用。谁能给我解释一下?

感谢任何帮助,并提前致谢。

最佳答案

您的答案就在此处的文档中 21.1 Defining Stored Programs

If you use the mysql client program to define a stored program containing semicolon characters, a problem arises. By default, mysql itself recognizes the semicolon as a statement delimiter, so you must redefine the delimiter temporarily to cause mysql to pass the entire stored program definition to the server.

关于mysql - 为什么用复合语句创建EVENT会出现这个错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37825627/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com