1.if语句
delimiter \ create procedure p1() begin declare i int default 0; if i = 1 then select 1; elseif i = 2 then select 2; else select 3; end if; end \ delimiter ;
2.循环
delimiter \ create procedure p1_while() begin declare num int; set num =0; while num < 10 do select num; set num = num +1; end while; end \ delimiter ;
delimiter \ create procedure p1_repeat() begin declare i int; set i = 0; repeat select i; set i =i +1; until i>5 end repeat; end \ delimiter ;
delimiter // declare i int default 0; loop_label: loop set i=i+1; if i<8 then iterate loop_label; end if; if i >=10 then leave loop_label; end if; select i; end loop loop_label; delimiter ;