欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

实际操作:如何在MySQL中运用游标

最编程 2024-08-05 07:54:57
...

begin
declare temp_user_id int default null;
declare stop int default 0;
#声明游标
 declare temp_cur cursor for select f_user_id from table_test where f_user_id=1;
 #声明游标的异常处理
 declare continue handler for sqlstate '02000' set stop=1;
 open temp_cur;
 fetch temp_cur into temp_user_id;
 #判断游标是否到达最后
 while stop<>1 do
 #各种判断
 #读取下一行的数据   
 fetch temp_cur into temp_user_id;  
 #循环结束  
 end while; 
 #关闭游标
 close temp_cur;
end

推荐阅读