oracle数据库update循环执行语句

--由于数据量比较大每次执行一个小时时报回滚段已满

--这里有两种方法来分批处理

1、declare
  maxrows number default 5000;
  p_id_table dbms_sql.Varchar2_Table;
  cursor acnt_first_cur is
    select t2.cert_number
          from tb_pnt_cust_551 t,party_centification t2
         where t.pty_id = t2.party_id
           and t2.cert_type = 1
           and t2.latn_id = 551
           and rownum < 2;
begin
  open acnt_first_cur;
  loop
    exit when acnt_first_cur%notfound;
    fetch acnt_first_cur bulk collect
      into p_id_table limit maxrows;
    forall i in 1 .. p_id_table.count
      update tb_pnt_cust_551 t3
         set t3.id_card = p_id_table(i);
    commit;
  end loop;
end;
/

 --------------------------------------------------------------------------------------------------------------

2、begin
for i in 1..1000 loop
update tb_pnt_cust_551 t
   set t.id_card =  (select cert_number from
       (select t2.party_id,max(t2.cert_number) cert_number
          from party_centification t2
         where t2.cert_type = 1
           and t2.latn_id = 551
         group by t2.party_id)
         where t.pty_id = t2.party_id ) t1
  where rownum < 1000
    and t.id_card is null;end loop;
end;
/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值