码迷,mamicode.com
首页 > 其他好文 > 详细

if-case-循环语句

时间:2018-03-24 20:42:29      阅读:155      评论:0      收藏:0      [点我收藏+]

标签:if语句   stat   nbsp   sts   roc   int   cal   state   hello   

IF语句

drop procedure if exists p_hello_world;  
create procedure p_hello_world(in v_id int)  
begin  
    if (v_id > 0) then  
        select > 0;  
    elseif (v_id = 0) then  
        select = 0;  
    else  
        select < 0;  
    end if;  
end;  
call p_hello_world(-9);  

Case语句

drop procedure if exists pro2;
delimiter //
create procedure pro2(in tid int(10))
begin 
    case tid
        when 1 then
            insert into test values(1,xjh,tx,15268335587);
        when 2 then 
            insert into test values(2,zjj,tx,15268335587);
    end case;
end//
delimiter ;

如果case中未处理的参数则会报 Case not found for CASE statement 错误

循环

  WHILE-DO…END-WHILE循环

delimiter //
create procedure pro2()
begin 
    set  @i = 0;
    while @i<10 do
        insert into test (tid,tname)values(@i,批量);
        set @i=@i+1;
    end while;
end//
delimiter ;

  REPEAT...END REPEAT

delimiter //
create procedure pro2()
begin 
    set  @i = 0;
    repeat
        insert into test (tid,tname)values(@i,批量);
        set @i = @i + 1;
    UNTIL @i< 10 end repeat;
end//
delimiter ;

  LOOP...END LOOP

delimiter //
create procedure pro2()
begin 
    set  @i = 0;
    loop_pos:loop
        insert into test (tid,tname)values(@i,批量);
        set @i = @i + 1;
        if @i =2 then
            leave loop_pos;
        end if;
    end loop;
end//
delimiter ;

 

if-case-循环语句

标签:if语句   stat   nbsp   sts   roc   int   cal   state   hello   

原文地址:https://www.cnblogs.com/FlyBlueSky/p/8641025.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!