loop语句
leave语句
用来从标注的流程构造中退出,通常和 BEGIN ... END 或者循环一起使用。下面是一个使用 LOOP 和 LEAVE 的简单例子 , 退出循环:
-- 计算从1加到n的值 ------> loop ... leave
create procedure pro_test10(n int)
begin
declare total int default 0;
c:loop
set total = total + n;
set n = n -1;
if n <= 0 then
leave c;
end if;
end loop c;
select total;
end$