MySQL 有输入输出参数的存储过程实例
程序员文章站
2023-12-12 20:29:52
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'
复制代码 代码如下:
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'