码迷,mamicode.com
首页 > 其他好文 > 详细

事件游标

时间:2015-03-31 12:07:00      阅读:88      评论:0      收藏:0      [点我收藏+]

标签:

 

事件游标:

BEGIN
DECLARE cx_id INT(10);
DECLARE t_query VARCHAR(500);
DECLARE done INT DEFAULT FALSE;
DECLARE cur CURSOR FOR SELECT junda_pmcloud.t_ipguard_status.ipguard_id FROM junda_pmcloud.t_ipguard_status;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
OPEN cur;
read_loop:LOOP
FETCH cur INTO cx_id;
IF done THEN
LEAVE read_loop;
END IF;
SELECT TIMESTAMPDIFF(SECOND, (SELECT t_ipguard_status.updatetime from t_ipguard_status where t_ipguard_status.ipguard_id=cx_id) ,now()) INTO @t_time;
UPDATE t_ipguard_status set t_ipguard_status.is_active=0 WHERE @t_time>60 and t_ipguard_status.ipguard_id=cx_id;

END LOOP;
CLOSE cur;
END

 

创建一个事件,对某个表的内容进行遍历循并当时间差>60时,进行数据库操作。

当在END LOOP; 前添加 kill cx_id; 则只执行一次。而不是遍历。

 

事件游标

标签:

原文地址:http://www.cnblogs.com/hzijone/p/4380168.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!