语法:
IF condition1 THEN
{...statements to execute when condition1 is TRUE...}
[ ELSEIF condition2 THEN
{...statements to execute when condition2 is TRUE...} ]
[ ELSE
{...statements to execute when both condition1 and condition2 are FALSE...} ]
END IF;
实例:
CREATE PROCEDURE sp_search_user(IN NAME VARCHAR(20))
BEGIN
IF NAME THEN
SELECT * FROM `user` where name like NAME;
ELSE
SELECT * FROM `user`;
END IF;
END;
执行:
call sp_search_user('zhen')