lundi 29 décembre 2014

MySQL IF...THEN syntax error

I've been trying to work with the IF statement in MySQL (v5.6.13) without any success. I've eventually pared my code back to the simple example below, which still doesn't work:



IF 10>1 THEN
SELECT 10;
END IF;


When I run this, it gives me the following error:



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 10>1 THEN
SELECT 10' at line 1


I did wonder whether it was something to do with the MySQL client I'm using (Sequel Pro), but I get exactly the same message running from the command line.


Am I making some kind of ridiculously simple mistake that I just can't see? Or does anyone have any suggestions as to what might be causing the error? Any help would be gratefully received!


Aucun commentaire:

Enregistrer un commentaire