创建存储过程
mysql> delimiter $ -- delimiter $是设置 $为命令终止符号,代替默认的分号,因为分号有其他用处.
mysql> create procedure sp_test(IN pi_id int, OUT po_name varchar(10))
-> begin
-> select * from test.tb_test;
-> select tb_test.name into po_name from test.tb_test where tb_test.id = pi_id;
-> end
-> $
Query OK, 0 rows affected (0.00 sec)
mysql> delimiter ; -- 恢复分号作为分隔终止符号
5.调用存储过程
mysql> set @po_name='';
Query OK, 0 rows affected (0.00 sec)
mysql> call sp_test(1,@po_name);