示例:
mysql> create procedure nl(inout arg int)
-> begin
-> declare i int default 0;
-> case i
-> when 1 then
-> select 'sina';
-> when 2 then
-> select 'baidu';
-> else
-> select 'ali';
-> end case;
-> end;
-> $
Query OK, 0 rows affected (0.22 sec)
mysql> \d;
mysql> set @s =2;
Query OK, 0 rows affected (0.05 sec)
mysql> call nl(@s);
+-----+
| ali |
+-----+
| ali |
+-----+
1 row in set (0.09 sec)
Query OK, 0 rows affected (0.10 sec)
拓展阅读:
MySQL存储过程详解
MySQL带参数的存储过程小例子
一点实例明白mysql数据库存储过程
mysql存储过程详细教程