存储过程传入参数

delimiter '//'/**将结束符设置为双斜杆**/
create procedure pout(OUT p_out int)/**创建存储过程,p_out是传入的int类型值**/
 begin/**开始**/
 select p_out;/**打印P_out的值为null**/
 set p_out =2;/**设置p_out的值为2**/
 select p_out;/**打印P_out的值为2**/
END;/**结束**/
///**结束**/
 delimiter ';'/**--将结束符设置为;**/
 set @p_out=1;/**--设置p_out 为1**/
 call pout(@p_out);/**--调用存储过程**/
SELECT @p_out;/**--输出为2**/
drop PROCEDURE pout;/**删除存储过程**/

1.结论:存储过程OUT定义的参数不接受外部的值,但存储过程能改变外部的值。

delimiter '//'/**将结束符设置为双斜杆**/
create procedure poin(IN p_In int)/**创建存储过程,p_In是传入的int类型值**/
 begin/**开始**/
 select p_In;/**打印P_In的值为1**/
 set p_In =2;/**设置p_In的值为2**/
 select p_In;/**打印P_In的值为2**/
END;/**结束**/
///**结束**/
 delimiter ';'/**--将结束符设置为;**/
 set @p_In=1;/**--设置p_In 为1**/
 call poin(@p_In);/**--调用存储过程**/
SELECT @p_In;/**--输出为1**/

2.结论:IN定义的参数能传入到存储过程内部,但不能改变外部的值。

delimiter '//'/**将结束符设置为双斜杆**/
create procedure pout(INOUT p_out int)/**创建存储过程,p_out是传入的int类型值**/
 begin/**开始**/
 select p_out;/**打印P_out的值为1**/
 set p_out =2;/**设置p_out的值为2**/
 select p_out;/**打印P_out的值为2**/
END;/**结束**/
///**结束**/
 delimiter ';'/**--将结束符设置为;**/
 set @p_out=1;/**--设置p_out 为1**/
 call pout(@p_out);/**--调用存储过程**/
SELECT @p_out;/**--输出为2**/

3.INOUT类型既能传入值,也能改变外部的值。

猜你喜欢

转载自blog.csdn.net/qq_15875773/article/details/82629445
今日推荐