Oracle 每五千条执行一次的sql语句

今天碰到一个问题,更新历史数据时,由于数据库表数据量太大,单行更新速度很慢,要求每五千条执行一次提交进行更新。执行SQL如下:

 

declare
  i_count int;
  i_large int;
begin
  i_count := 1;
  select ceil(count(1) / 5000)
    into i_large
    from tablename ch;
  while i_count <= i_large loop  
  
    update tablename a
       set a.aa   = i_count
       where a.aa is  null
       and rownum <= 5000;
     
    commit;
    i_count := i_count + 1;
  end loop;
end;

  这样写执行效率还可以。

posted @ 2017-06-06 17:46  jason.bai  阅读(1798)  评论(0编辑  收藏  举报