成都创新互联网站制作重庆分公司

MySQL游标的嵌套使用方法

本篇内容主要讲解“MySQL游标的嵌套使用方法”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“MySQL游标的嵌套使用方法”吧!

创新互联公司是专业的固原网站建设公司,固原接单;提供成都网站设计、网站制作,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行固原网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!

前几天群里有人问MySQL的游标能不能嵌套使用,想当然地以为不能,后来试了下,居然可以,唉,不能随便想当然啊。例子如下:

CREATE PROCEDURE curdemo()
   NOT DETERMINISTIC
   CONTAINS SQL
   SQL SECURITY DEFINER
   COMMENT '
BEGIN
 declare done1,done2 int default 0;
 declare name1,name2 varchar(20);
 declare id1,id2 int;

 declare cur1 cursor for select id,name from test1;
 declare continue handler for not found set done1 = 1;

 open cur1;

 repeat
   fetch cur1 into id1, name1;
   if not done1 then
     insert into test3(name) values(name1);
     begin
     declare cur2 cursor for select id,name from test2;
     declare continue handler for not found set done2 = 1;
     open cur2;
     repeat
       fetch cur2 into id2,name2;
       if not done2 then
          insert into test3(name) values(name2);
       end if;
     until done2 end repeat;
     close cur2;
     set done2=0;
     end;
   end if;
 until done1 end repeat;
 close cur1;

 commit;
END;

到此,相信大家对“MySQL游标的嵌套使用方法”有了更深的了解,不妨来实际操作一番吧!这里是创新互联网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!


当前名称:MySQL游标的嵌套使用方法
文章URL:http://cxhlcq.com/article/pisdce.html

其他资讯

在线咨询

微信咨询

电话咨询

028-86922220(工作日)

18980820575(7×24)

提交需求

返回顶部