mysql 游标套游标实现方法



DECLARE done INT DEFAULT 0;  
   DECLARE curl CURSOR FOR select  a.pursuerid,a.personid,a.personcode,a.crfversion,b.pursuercode  from    edm_person a 
                            join edm_pursuer b on a.projectid=b.projectid and a.pursuerid=b.pursuerid where  a.projectid =p_projectid  and if(CHAR_LENGTH(p_personcode)>0,a.personcode=p_personcode,1=1)  LIMIT pageNum,pageSize;
    DECLARE cur2 cursor for SELECT  periodid,name,periodtype  from  edm_period  where  projectid =p_projectid ;

 DECLARE CONTINUE HANDLER FOR NOT FOUND SET done=1;  
    
  
 -- 插入表单
    OPEN curl;
     my_loop:LOOP  
        FETCH curl INTO v_pursuerid,v_personid,v_personcode,v_crfversion,v_pursuername;  


        IF done=1 THEN  
          LEAVE my_loop;  
        END IF;  
     
        begin
             declare _inner tinyint(1) default 0;  
             declare cur_param cursor for SELECT periodid,periodseq  from   
                                (select  projectid,periodid,0 as periodseq from  edm_period  where projectid=p_projectid  and   periodtype=0  union
                              select  projectid,periodid,periodseq from  edm_form_status  where projectid=p_projectid   and personid=v_personid and  periodseq>0  and formid=0 ) a ;
            declare continue handler for not found set _inner = 1;   
            open cur_param;  

            loop_yyy:loop  
                fetch cur_param into v_periodid,v_periodseq;  
                if _inner=1 then  
                    leave loop_yyy;  
                end if;  
   
  INSERT into temp_visit_status_list(projectid,statustype,pursuerid,pursuername,personid,crfversion,personcode,periodid,periodcode,periodseq,flag)
                VALUES(p_projectid,p_stautstype,v_pursuerid,v_pursuername,v_personid,v_crfversion,v_personcode,v_periodid,CONCAT(v_periodid,v_periodseq),v_periodseq,v_flag);


                set _inner = 0; 
            end loop loop_yyy;  
            
          
        end ;
 


      set  done=0;
     END LOOP; 
 CLOSE curl;  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值