0

我正在使用以下代码运行此事件 IF CURRENT_TIME() = '23:50:00'

但是这样做,每一秒都必须将时间与服务器时间进行比较。我们可以在没有条件的情况下实现它吗

drop event OEAuditEvent;

DELIMITER $$

CREATE EVENT OEAuditEvent
ON SCHEDULE EVERY 1 SECOND
STARTS '2012-08-30 09:00:10'

DO
BEGIN

DECLARE a CHAR(20);
DECLARE b,c,d INT;
DECLARE done INT DEFAULT FALSE;

IF CURRENT_TIME() = '23:50:00' THEN
begin 

DECLARE cur CURSOR FOR select OE_User,count(OE_User) from RNCM_Status where date(OE_Date)=CURDATE() group by OE_User; 
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;

OPEN cur;
read_loop: LOOP


FETCH cur INTO a, b;

SET c=ceil((b*5)/100);
insert into test values(a,b);
IF done THEN

          LEAVE read_loop;
ELSE
          insert into OE_Audit(MDN,CAF,UploadedDate,OEUser,OEDate,UserCount,QCCount,intime) select MDN,CAF,UploadedDate,OE_User,OE_Date,b,c,now() from RNCM_Status where OE_User=a and date(OE_Date)=CURDATE() order by rand() limit c;
    END IF;

END LOOP;
CLOSE cur;
end ;
END IF;



END $$

DELIMITER ;
4

1 回答 1

1

为什么不创建事件本身以在每天 23:00 运行并完全删除 IF?

CREATE EVENT OEAuditEvent
ON SCHEDULE EVERY 1 DAY
STARTS '2012-08-30 23:00:00'
于 2012-09-03T11:54:53.990 回答