DELIMITER $
CREATE PROCEDURE getDailyDraw()
BEGIN
DECLARE MSG_ID integer;
DECLARE AuthorEmail Varchar(255);
SELECT id,author_email INTO MSG_ID,AuthorEmail FROM MessageInfo
WHERE accepted = true
and mod_date > date_sub(now(), interval 24 HOUR) order by rand() limit 1;
insert into dailydraw (winning_date,author_email) values (now(),AuthorEmail);
END$
---Create Database Event to execute procedure everyday
SET GLOBAL event_scheduler = ON;
CREATE EVENT Get_DailyDraw ON SCHEDULE EVERY 1 DAY
DO CALL getUserInfo();
---------------------------------------------------------------------------
mysql实现存储过程和Event
最新推荐文章于 2021-06-28 11:42:03 发布