drop procedure if exists make_sum;create procedure make_sum() begin declare num int default 0; declare res int default 0; while num<=100 do set res = res + num; set num = num + 1; end while; select res;end;call make_sum();复制代码
loop
drop procedure if exists make_sum;create procedure make_sum() begin declare num int default 0; declare res int default 0; myloop:loop set res = res + num; set num = num + 1; if num > 100 then leave myloop; end if; end loop; select res;end;call make_sum();复制代码
repeat
drop procedure if exists make_sum;create procedure make_sum() begin declare num int default 0; declare res int default 0; repeat set res = res + num; set num = num + 1; until num > 100 end repeat; select res;end;call make_sum();复制代码