MySQL存儲過程示例

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();

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章