1. Where loop
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 loop
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 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; $$;
The above is the content of MySQL Advanced Three - Loop Statement, more For related content, please pay attention to the PHP Chinese website (www.php.cn)!