Mysql储存过程3:if语句
--if/else语句 if 条件 then SQL语句 else SQL语句
elseif
SQL语句 end if; create procedure test1( number int ) begin if number > 10 then select user(); else select 'please input a number > 10'; end if; end$
mysql> create procedure test1( -> number int -> ) -> begin -> if number > 10 then -> select user(); -> else -> select 'please input a number > 10'; -> end if; -> end$ Query OK, 0 rows affected (0.00 sec) mysql> call test1()$ ERROR 1318 (42000): Incorrect number of arguments for PROCEDURE test.test1; expected 1, got 0 mysql> call test1(11)$ +----------------+ | user() | +----------------+ | root@localhost | +----------------+ 1 row in set (0.00 sec) Query OK, 0 rows affected (0.01 sec) mysql> call test1(1)$ +----------------------------+ | please input a number > 10 | +----------------------------+ | please input a number > 10 | +----------------------------+ 1 row in set (0.00 sec) Query OK, 0 rows affected (0.01 sec) mysql>