MySQL IF文

559 ワード

構文:
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')