当前位置:Gxlcms > mysql > MySQL高级三——循环语句

MySQL高级三——循环语句

时间:2021-07-01 10:21:17 帮助过:60人阅读

1、where循环

create procedure p_addnum()
begin
declare i int default 1;
declare addresult int default 0;
while i <= 100 do
	set addresult = addresult + i;
	set i = i + 1;
end while;
select addresult;
end;
$$;

2、repeat循环

create procedure p_updatenum()
begin
declare imin int default 1;
declare value int default 1;
declare imax int default 100;
repeat
	select value;
	set value = value + 1;
	set imin = imin + 1;
	until imin > imax
end repeat;
end;
$$;

3、loop循环

create procedure p_updateloop()
begin
declare imin int default 1;
declare value int default 1;
declare imax int default 100;
myloop:loop
	select value;
	set value = value + 1;
	set imin = imin + 1;
	if imin > imax then
	leave myloop;
	end if;
end loop;
end;
$$;

以上就是MySQL高级三——循环语句的内容,更多相关内容请关注PHP中文网(www.gxlcms.com)!

人气教程排行