MysqL存储过程中游标遍历的方法:首先取值,取多个字段;然后遍历数据结束标志,将结束标志绑定到游标,代码为【DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;】。
MysqL存储过程中游标遍历的方法:
CREATE defineR=`root`@`%` PROCEDURE `updStatus`()BEGINDECLARE startTime DATETIME;DECLARE endTime DATETIME;DECLARE curTime DATETIME;DECLARE ID VARCHAR(36); DECLARE estatus VARCHAR(4); -- 遍历数据结束标志 DECLARE done INT DEFAulT FALSE; -- 游标 DECLARE examIDs CURSOR FOR SELECT EXAM_ID FROM t_exam WHERE EXAM_STATUS = 1 or EXAM_STATUS = 2; -- 将结束标志绑定到游标 DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;OPEN examIDs; -- 遍历 read_loop: LOOP-- 取值 取多个字段FETCH NEXT from examIDs INTO ID;IF done THENLEAVE read_loop;END IF;SELECT EXAM_STATUS INTO estatus FROM t_exam WHERE EXAM_ID = ID ;IF estatus =1 THENSELECT Now() INTO curTime;SELECT EXAM_START_TIME INTO startTime from t_exam WHERE EXAM_ID = ID ;SELECT EXAM_END_TIME INTO endTime from t_exam WHERE EXAM_ID = ID ;IF curTime >= startTime AND endTime > curTime THENUPDATE t_exam SET EXAM_STATUS = 2 WHERE EXAM_ID = ID;ELSEIF curTime >= endTime THENUPDATE t_exam SET EXAM_STATUS = 3 WHERE EXAM_ID = ID;END IF;ELSESELECT Now() INTO curTime;SELECT EXAM_END_TIME INTO endTime from t_exam WHERE EXAM_ID = ID ;IF curTime >= endTime THENUPDATE t_exam SET EXAM_STATUS = 3 WHERE EXAM_ID = ID;END IF;END IF; END LOOP; CLOSE examIDs;END
总结更多相关免费学习推荐:mysql教程(视频)
以上是内存溢出为你收集整理的mysql存储过程中游标如何遍历全部内容,希望文章能够帮你解决mysql存储过程中游标如何遍历所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)