MySQL 定时任务
--- 每24小时执行一次 24*60*60=86400
create event if not exists e_la on schedule every 86400 second on completion preserve do call sp_lasq();
----关闭事件任务
alter event sp_lasq ON COMPLETION PRESERVE DISABLE;
-----开户事件任务
2.alter event sp_lasq ON COMPLETION PRESERVE ENABLE;
mysql存储过程
CREATE PROCEDURE sp_lasq() BEGIN declare caseid VARCHAR(50); declare case_cursor cursor for select id from cases where cases.`status`='1' and to_days(now()) - to_days(cases.complainDate)>5; open case_cursor; case_cursor:loop fetch case_cursor into caseid; insert into case_shlc(caseid,userid,option,time,status) values (caseid ,'02debc9f-53cd-4bc9-887b-49ffc4e925f2','批量立案',CONCAT(SYSDATE(),'') ,'3') ; update cases set cases.`status` ='3' where cases.id = caseid ; end loop case_cursor; close case_cursor; END;
本文原创,转载必追究版权。