begin
DECLARE tf_UserName varchar(32);
DECLARE tf_enddate DATETIME;
DECLARE tf_difftime INT(11);
DECLARE STOP INT DEFAULT 0;
DECLARE AfterDate DATETIME; //定义变量时间
DECLARE cur CURSOR FOR SELECT UserName,stopdate FROM userinfo where status=10000 and stopdate'0000-00-00';
DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET STOP=1;
DECLARE EXIT HANDLER FOR SQLEXCEPTION ROLLBACK;
OPEN cur;
START TRANSACTION;
FETCH cur INTO tf_UserName,tf_enddate;
WHILE STOP 1 DO
SET AfterDate = date_add(tf_enddate, interval 12 hour); //确定需要增加的时间
SET tf_difftime = UNIX_TIMESTAMP(AfterDate) - UNIX_TIMESTAMP(NOW());
UPDATE radreply SET VALUE=tf_difftime WHERE UserName=tf_UserName AND Attribute='Idle-Timeout';
UPDATE radreply SET VALUE=tf_difftime WHERE UserName=tf_UserName AND Attribute='Session-Timeout';
COMMIT;
FETCH cur INTO tf_UserName,tf_enddate;
END WHILE;
CLOSE cur;
end