mysql流程控制有哪些_MySQL流程控制和存储过程介绍

/*

定义变量

方式1:set @变量名=值;

方式2:select 值 into @变量名;

方式3:declare 变量名 类型(字符串类型加范围) default 值;

in参数 入参的值会仅在存储过程中起作用

out参数 入参的值会被置为空,存储中计算的值会影响外面引用该变量的值

inout参数 入参的值不会被置为空,存储中计算的值会影响外面引用该变量的值

*/

use mysql;

/*创建1个存储过程*/

delimiter $$

DROP PROCEDURE IF EXISTS porc_person_02;

CREATE PROCEDURE porc_person_02(IN p1 INT, OUT p2 INT, INOUT p3 VARCHAR(20))

BEGIN

DECLARE innerp1 VARCHAR(10) DEFAULT 'this is innerp1';

DECLARE innerp2 VARCHAR(10) DEFAULT 'this is innerp2';

SET p1=10;

SET p2=20;

SET p3='this is 字符串';

if p1=10 then

select 'p1 is 10';

end if;

if p1=p2 then

select 'p1=p2';

else

select p1,p2,p3;

end if;

case p3

when 'a' then

select 'p3 is a';

when 'b' then

select 'p3 is b';

when 'c' then

select 'p3 is c';

else

select p3;

end case;

/*条件不满足会被终止*/

while p1>4

do

set p1=p1-1;

end while;

select p1;

checka:loop

set p1=p1+1;

if p1=14 then

leave checka;

end if;

end loop;

select p1;

/*条件满足会被终止*/

repeat

set p1=p1-1;

until p1=6

end repeat;

select p1;

END;

$$

set @p_in=3;

set @p_out=2;

set @p_inout='b';

select 'check procedure' into @p4;

call porc_person_02(@p_in,@p_out,@p_inout);

select @p_in,@p_out,@p_inout,@p4;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值