Mysql带返回值与不带返回值的2种存储过程

时间:2023-03-09 06:46:11
Mysql带返回值与不带返回值的2种存储过程

过程1:带返回值:

1 drop procedure if exists proc_addNum;
2 create procedure proc_addNum (in x int,in y int,out sum int)
3 BEGIN
4 SET sum= x + y;
5 end

然后,执行过程,out输出返回值:

1 call proc_addNum(2,3,@sum);
2 select @sum;

过程2:不带返回值:

Mysql带返回值与不带返回值的2种存储过程
1 drop procedure if exists proc_addNum;
2 create procedure proc_addNum (in x int,in y int)
3 BEGIN
4 DECLARE sum int;
5 SET sum= x + y;
6 SELECT sum;
7 end
Mysql带返回值与不带返回值的2种存储过程

执行过程:

1 call proc_addNum(2,3);