欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

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

程序员文章站 2022-04-14 19:59:12
...
第一次写事件调用存储过程,在网上找了一些资料,特此做下总结,巩固一下:

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

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

本文主要出自:

以上就是学习mysql事件如何调用存储过程的方法的详细内容,更多请关注其它相关文章!