嵌套游标

CREATE OR REPLACE PROCEDURE p_temp_count_orga
IS
   v_orga_id varchar2(20)  :='';
  
   -- 查询xxx市直 + 乡 id
   CURSOR c_sms_batch is
    select t.orga_id, t.orga_name
      from sys_organize t
     where t.orga_parentid2 IS NULL
       AND t.orga_parentid = '2013020400000015'
       AND t.virtual_flag = '1';
      
      CURSOR c_sms_batch2(vid varchar2 ) is  
        select  orga_id,orga_name from (
          select o.orga_id,o.orga_name
            from sys_organize o
           where 1 = 1
          CONNECT BY O.ORGA_PARENTID = PRIOR O.ORGA_ID
           START WITH O.ORGA_PARENTID = vid
          union all
          select o.orga_id ,o.orga_name from sys_organize o where o.orga_parentid2 = vid
          );
 

BEGIN

   FOR r_sms IN c_sms_batch
   LOOP
    BEGIN
     
      FOR r_sms2 IN c_sms_batch2(r_sms.orga_id)
        LOOP
          BEGIN
                 insert into tttemp (id) values ( r_sms2.orga_id);
          END;
      END LOOP;
    END;
   END LOOP;
   
    DBMS_OUTPUT.put_line ('ok  ... ');
   COMMIT;
EXCEPTION
   WHEN OTHERS
   THEN
      BEGIN
         DBMS_OUTPUT.put_line (SQLERRM);
         ROLLBACK;
      END;
END;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值