一、条件语句

  if……then

  elseif……then

  else

  end if;

二、循环语句,有三种

  while……do……

  repeat……until……

  loop……leave……

-- loop--------------------------------------------------
delimiter \\
drop procedure if exists proc_loop \\
create procedure proc_loop()
begin
    declare num int default 0;
    loop_label:loop
        select num;
        set num=num+1;
        if num>=10 then
            leave loop_label;
        end if;
    end loop;
end \\
delimiter;

call proc_loop();

-- repeat----------------------------------------------
delimiter \\
drop procedure if exists proc_repeat \\
create procedure proc_repeat()
begin
    declare num int;
    set num=0;
    repeat
        select num;
        set num=num+1;
        until num>=10
    end repeat;
end \\
delimiter;

call proc_repeat();

-- while------------------------------------------------
delimiter \\
drop procedure if exists proc_while \\
create procedure proc_while()
begin
    declare num int;
    set num=0;
    while num<10 do
        select num;
        set num=num+1;
    end while;
end \\
delimiter;

call proc_while();
条件语句与循环语句