三、MySQL 存储过程参数(inout)
MySQL 存储过程 inout 参数跟 out 类似,都可以从存储过程内部传值给调用者。不同的是:调用者还可以通过 inout 参数传递值给存储过程。
drop procedure if exists pr_param_inout; create procedure pr_param_inout ( inout id int ) begin select id as id_inner_1; -- id 值为调用者传进来的值 if (id is not null) then set id = id + 1; select id as id_inner_2; else select 1 into id; end if; select id as id_inner_3; end;
set @id = 10; call pr_param_inout(@id); select @id as id_out;
mysql> set @id = 10; mysql> mysql> call pr_param_inout(@id); +------------+ | id_inner_1 | +------------+ | 10 | +------------+ +------------+ | id_inner_2 | +------------+ | 11 | +------------+ +------------+ | id_inner_3 | +------------+ | 11 | +------------+ mysql> mysql> select @id as id_out; +--------+ | id_out | +--------+ | 11 | +--------+
从结果可以看出:我们把 @id(10),传给存储过程后,存储过程最后又把计算结果值 11(id_inner_3)传回给调用者。 MySQL 存储过程 inout 参数的行为跟 C 语言函数中的引用传值类似。
通过以上例子:如果仅仅想把数据传给 MySQL 存储过程,那就使用“in” 类型参数;如果仅仅从 MySQL 存储过程返回值,那就使用“out” 类型参数;如果需要把数据传给 MySQL 存储过程,还要经过一些计算后再传回给我们,此时,要使用“inout” 类型参数。
总结
以上就是本文关于mysql数据存储过程参数实例详解的全部内容,希望对大家了解MySQL有所帮助。感兴趣的朋友可以继续参阅本站:解析MySQL中存储时间日期类型的选择问题、MySQL 声明变量及存储过程分析等,有什么问题可以随时留言,小编会及时回复大家的。感谢朋友们对本站的支持!
更多Mysql内容来自木庄网络博客
标签:Mysql
相关阅读 >>
更多相关阅读请进入《mysql》频道 >>

数据库系统概念 第6版
本书主要讲述了数据模型、基于对象的数据库和XML、数据存储和查询、事务管理、体系结构等方面的内容。