本节学习下mysql中case when语句的用法,看看在存储过程中如何调用。
代码如下:
mysql> delimiter $$ mysql> CREATE PROCEDURE myProc(customer_status VARCHAR(10)) -> BEGIN //创建mysql存储过程 -> -> CASE customer_status //case when语句用法 -> WHEN 'PLATINUM' THEN -> select 'PLATINUM'; -> -> WHEN 'GOLD' THEN -> select 'GOLD'; -> -> WHEN 'SILVER' THEN -> select 'SILVER'; -> -> WHEN 'BRONZE' THEN -> select 'BRONZE'; -> END CASE; -> END$$ Query OK, 0 rows affected (0.00 sec) mysql> delimiter ; mysql> call myProc('BRONZE'); //调用存储过程 +--------+ | BRONZE | +--------+ | BRONZE | +--------+ 1 row in set (0.00 sec) Query OK, 0 rows affected (0.00 sec) mysql> call myProc('GOLD'); //调用存储过程 +------+ | GOLD | +------+ | GOLD | +------+ 1 row in set (0.00 sec) Query OK, 0 rows affected (0.00 sec) mysql> drop procedure myProc; //删除mysql存储过程 Query OK, 0 rows affected (0.00 sec)