您的当前位置:首页学习mysql事件如何调用存储过程的方法

学习mysql事件如何调用存储过程的方法

2020-11-09 来源:爱问旅游网

第一次写事件调用存储过程,在网上找了一些资料,特此做下总结,巩固一下:

事件调用存储过程主要有三种:

(1)创建事件马上执行,调用存储过程

CREATE EVENT if not exists Event_Stat_Daily
on schedule EVERY 1 DAY
on completion preserve
do call cp_Stat_VideoData();

(2)每天定时执行事件,调用存储过程

CREATE EVENT Event_Stat_Daily
ON SCHEDULE EVERY 1 DAY STARTS '2017-03-01 02:00:00'
ON COMPLETION PRESERVE
ENABLE
DO call cp_Stat_VideoData();

(3)没有调用方法或者存储过程,直接在事件里面逻辑操作

DELIMITER | CREATE EVENT e5 ON SCHEDULE EVERY 1 DAY STARTS '2017-03-01 02:00:00' ON COMPLETION PRESERVE DO BEGIN declare yestday date; set yestday=date(date_add(NOW(), interval -1 day)); if exists(select Id from Stat_VideoHits where AddDate = yestday) THEN delete from Stat_VideoHits where AddDate=yestday; end if;

insert into Stat_VideoHits(Id,VideoId,Times,AddDate) select uuid(), VideoId,COUNT(1),AddDate from Coll_VideoHits where AddDate = yestday group by VideoId;

DELETE from Sum_VideoHits;

insert into Sum_VideoHits(Id,VideoId,Times,UpdateDate) select uuid(),VideoId,sum(Times),now() from Stat_VideoHits group by VideoId;

END | DELIMITER ;

本文主要出自:

显示全文