drop procedure if exists p_hello_world;
create procedure p_hello_world()
begin
declare i int;#定義變量
declare j int;
declare x date;
declare y date;
set i = 0;
set j = 1;
#循環體開始
add_loop:loop
#每次給i加1
set i = i+1;
set j = j+1;
if i > 29826 then
#當i大於時結束循環體
leave add_loop;
else
SELECT sign_time INTO x FROM jsj_sign WHERE id = i;
SELECT sign_time INTO y FROM jsj_sign WHERE id = j;
if ( x > y ) then
UPDATE jsj_sign set sign_time = date_add(sign_time, interval 1 day) where id = j;
end if;
end if;
#循環體結束
end loop add_loop;
end;
call p_hello_world();