Monday, 30 April 2012

Update, delete from a huge table with intermittent commits


loop
      update tab1 set col1 = 'value2'
             where rowid = c1.rowid;
 
      i := i + 1;              -- Commit after every X records
      if i > 10000 then
         commit;
         i := 0;
      end if;
 
  end loop;
  commit;
end;
/
 
-- Note: More advanced users can use the mod() function to commit every N rows. 
--       No counter variable required:
--
-- if mod(i, 10000) 
--    commit;
--    dbms_output.put_line('Commit issued for rows up to: '||c1%rowcount);
--  end if;

No comments:

Post a Comment