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

MySQL 有输入输出参数的存储过程实例

程序员文章站 2023-11-29 10:44:16
1、实例 复制代码 代码如下:delimiter // drop procedure if exists `test`.`p_getvalue` // create def...
1、实例
复制代码 代码如下:

delimiter //
drop procedure if exists `test`.`p_getvalue` //
create definer=`root`@`localhost` procedure `p_getvalue`(
in id varchar(20),out s varchar(20)
)
begin
if (length(id)=11) then select 'a_b_c_d' into s;
elseif(length(id)=8) then select 'a_b_c' into s;
elseif(length(id)=5) then select 'a_b' into s;
elseif(length(id)=2) then select 'a' into s;
end if;
select s;
end //
delimiter ;

2、调用
复制代码 代码如下:

call p_getvalue('11000112',@s)

3、结果
'a_b_c'