您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

mysql存储过程中游标如何遍历

2024/2/27 4:41:12发布14次查看
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存储过程中游标如何遍历的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product