0
点赞
收藏
分享

微信扫一扫

分支语句if else条件

f12b11374cba 2022-04-29 阅读 84
mysql

if 条件 then

       语句块1;

Else

       语句块2

end  if;

   delimiter  $$

   create  procedure  s2(in  i  int)

   begin

            if  i > 5 then

                 select  ‘哈哈’;

           else

                select  ‘呵呵’;

           end  if;

   end;

call s2(7);

存储过程中带有多个分支结构条件语句:即有多个if …else

If 条件 then

       语句块1;

Elseif 条件 then

       语句块2;

Elseif 条件 then

        语句块3;

Else

        语句块4;

End  if;

# 带参数实现输入两个值,比较大小

Delimiter $$

Create  procedure  s3(in  aa  int,in  bb  int)

Begin

        If  aa > bb  then

             Select  ‘a大于b’;

        Elseif  aa = bb  then

              Select  ‘a等于b’;

        Else

              Select  ‘a小于b’;

        End  if;

End;

Call s3(12,15);

# 分支语句中还可以进行嵌套

Delimiter  //

Create  procedure  s4(in  aa  int,in  bb  int)

Begin

        If  aa>bb  then

              If  aa-bb>5  then

                   Select  ‘ab大于5以上’;

              Else

                   Select  ‘ab大!’;

        Elseif  aa=bb  then

              Select  ‘a等于b’;

        Else

             Select  ‘a小于b’;

         End  if;

End;

Call  s4(25,20)

举报

相关推荐

0 条评论