IF语法错误

2ma*_*mac 5 mysql sql syntax if-statement syntax-error

我在遵循MySQL指南的IF语法时遇到语法错误.

我的查询是:

if 0=0 then select 'hello world'; end if;
Run Code Online (Sandbox Code Playgroud)

从逻辑上讲,这应该选择'hello world',但我得到了

ERROR 1064 (42000): 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 'if (0=0) then select 'hello world'' at line 1
ERROR 1064 (42000): 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 'end if' at line 1
Run Code Online (Sandbox Code Playgroud)

Dfa*_*ure 5

您的查询仅在存储过程/函数上下文中有效.见以供参考.