欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

MySQL存储过程相互调用并获得错误码示例

程序员文章站 2024-02-27 12:14:27
复制代码 代码如下: mysql> mysql> delimiter $$ mysql> mysql> create procedure mypro...
复制代码 代码如下:

mysql>
mysql> delimiter $$
mysql>
mysql> create procedure myproc()
-> modifies sql data
-> begin
-> declare l_status varchar(20);
->
-> call myproc1(l_status);
-> if l_status='duplicate entry' then
-> select concat('warning: using existing definition for location ') as warning;
-> end if;
-> end$$
query ok, 0 rows affected (0.00 sec)

mysql>
mysql> create procedure myproc1(out out_status varchar(30))
-> begin
-> set out_status = 'duplicate entry';
-> end$$
query ok, 0 rows affected (0.00 sec)

mysql>
mysql>
mysql> delimiter ;
mysql> call myproc();
+--------------------------------------------------+
| warning |
+--------------------------------------------------+
| warning: using existing definition for location |
+--------------------------------------------------+
1 row in set (0.00 sec)

query ok, 0 rows affected (0.01 sec)

mysql> drop procedure myproc;
query ok, 0 rows affected (0.00 sec)

mysql> drop procedure myproc1;
query ok, 0 rows affected (0.00 sec)

mysql>
mysql>