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

发布时间:2024-11-26 点击:83
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教程(视频)

阿里云服务器打不开网站吗
购买云服务器优惠券不能使用
北京怎样在网上注册网站
移动界面设计点滴
百度小程序的怎么做SEO?
阿里学生机云服务器优惠
什么是网站域名?网站域名是什么意思
云闪科技服务器购买