分析MySQL存储过程参数有三种类型(in、out、inout)
2022-11-12 09:30:31
内容摘要
这篇文章主要为大家详细介绍了分析MySQL存储过程参数有三种类型(in、out、inout),具有一定的参考价值,可以用来参考一下。
对此感兴趣的朋友,看看idc笔记做的技术笔记!一、MySQ
文章正文
这篇文章主要为大家详细介绍了分析MySQL存储过程参数有三种类型(in、out、inout),具有一定的参考价值,可以用来参考一下。
对此感兴趣的朋友,看看idc笔记做的技术笔记!
一、MySQL 存储过程参数(in) MySQL 存储过程 “in” 参数:跟 C 语言的函数参数的值传递类似, MySQL 存储过程内部可能会修改此参数,但对 in 类型参数的修改,对调用者(caller)来说是不可见的(not visible)。代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | <code> drop procedure if exists pr_param_in; create procedure pr_param_in ( in id int -- in 类型的 MySQL 存储过程参数 ) begin if (id is not null) then set id = id + 1; end if ; select id as id_inner; end ; set @id = 10; call pr_param_in(@id); select @id as id_out; mysql> call pr_param_in(@id); </code> |
代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | <code> drop procedure if exists pr_param_out; create procedure pr_param_out ( out id int ) begin select id as id_inner_1; -- id 初始值为 null 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_out(@id); select @id as id_out; mysql> set @id = 10; mysql> mysql> call pr_param_out(@id); </code> |
代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | <code> 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); </code> |
注:关于分析MySQL存储过程参数有三种类型(in、out、inout)的内容就先介绍到这里,更多相关文章的可以留意
代码注释