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.php.cn) !