Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IF syntax error

I'm getting a syntax error while following the MySQL guide for IF syntax.

My query is:

if 0=0 then select 'hello world'; end if;

Logically, this should select 'hello world', but instead I get

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
like image 868
2mac Avatar asked Feb 12 '16 15:02

2mac


1 Answers

Your query is only valid in a stored procedure/function context. See there for reference.

like image 172
Dfaure Avatar answered Oct 13 '22 19:10

Dfaure