用复合语句创建EVENT时为什么会发生此错误? [英] Why did this error happened when created EVENT with compound statement?

查看:107
本文介绍了用复合语句创建EVENT时为什么会发生此错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由此SO 问题.我对DELIMITER感到困惑.而且我还尝试了以下操作:

From this SO question. I got confused with DELIMITER. And I also tried something like following:

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

这使我出现了类似提到的问题的错误:

This got me error like mentioned question:

错误代码:1064 您的SQL语法有误;请查看与您的MySQL服务器版本相对应的手册,以获取在第5行的''附近使用正确语法的语法.

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:

And if I ran the sql following:

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

这项工作成功并成功创建了一个新的EVENT.

This worked and created a new EVENT sucessfully.

这两个sql之间的唯一区别是最后一个使用DELIMITER,所以我的问题是DELIMITER在这里工作的原因.有人可以向我解释吗?

The only difference between these two sql is the last one used DELIMITER, so my question is why DELIMITER works here. Can anyone explain to me?

我们将不胜感激,在此先感谢您.

Any help is appreciated and thanks in advance.

推荐答案

这确实很琐碎,但很难解释.

It is real trivial, but hard to explain.

开箱即用的分隔符是; ...这就是mysql知道语句已结束的方式.但是诸如存储过程,事件,函数之类的东西中有很多语句.它需要一个外部包装器来使整个事情知道它在哪里开始和在哪里结束.

The delimiter out of the box is a ; ... That is how mysql knows the statement has ended. But things like stored procedures, events, functions have many statements in them. It needs an outer wrapper for the whole thing to know where it begins and where it ends.

因此,您将开始的分隔符重置为奇怪的内容,例如$$,将$$放在END之后,然后重置为出厂设置,以便与;对话

So, you reset the delimiter at the beginning to something bizarre, like $$, put that $$ right after the END, then reset back to factory so to speak to ;

在创建存储过程,事件,函数,触发器的过程中,您将始终遇到错误1064,而没有错误.而且,您将花费大量时间追逐尾巴,以查找不存在的语法错误.好吧,经常.实际上,它缺少DELIMITER包装器.

You are going to come up with Error 1064 all the time without it for the creation of stored procedures, events, functions, triggers. And you will burn a lot of time chasing your tail looking for the syntax error that is not there. Well, quite often. When in reality it lacks the DELIMITER wrapper.

这篇关于用复合语句创建EVENT时为什么会发生此错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆