美文网首页
MySQL流程控制,只能在存储过程中使用

MySQL流程控制,只能在存储过程中使用

作者: f68c8a455b56 | 来源:发表于2018-09-21 12:25 被阅读11次

    IF ELSE 控制语句为例:

    set @a = 1;
    if @a = 1 then
    select* from DB1;
    end if;
    
    执行报错
    drop procedureif exists curdemo;
    create procedure curdemo()
    begin
        set @a = 1;
        if @a = 1 then
        select* from WXLogon;
        end if;
    end;
    
    call curdemo();
    
    存储过程执行成功

    注意elseif的写法:

    if @a = 1 then
      select * from db1;
    elseif @a = 2 then
      select* from db2;
    end if;
    

    或者 else if:

    if @a = 1 then
      select * from db1;
    else
      if @a = 2 then
        select* from db2;
      end if;
    end if;
    

    相关文章

      网友评论

          本文标题:MySQL流程控制,只能在存储过程中使用

          本文链接:https://www.haomeiwen.com/subject/wvyanftx.html