Why did this error happened when created EVENT with compound statement?

前端 未结 2 604
生来不讨喜
生来不讨喜 2021-01-28 11:08

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
BEG         


        
2条回答
  •  误落风尘
    2021-01-28 12:08

    It is real trivial, but hard to explain.

    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.

    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 ;

    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.

提交回复
热议问题