类似语法上的问题,其实可以参考一下手册中的说明和例子。
MySQL 5.4 Reference Manual12.8.6.1. IF Statement
IF search_condition THEN statement_list
[ELSEIF search_condition THEN statement_list] ...
[ELSE statement_list]
END IF
IF implements a basic conditional construct. If the search_condition evaluates to true, the corresponding SQL statement list is executed. If no search_condition matches, the statement list in the ELSE clause is executed. Each statement_list consists of one or more statements.
Note
There is also an IF() function, which differs from the IF statement described here. See Section 11.3, “Control Flow Functions”.
An IF ... END IF block, like all other flow-control blocks used within stored programs, must be terminated with a semi