Search code examples
oracle-databaseoracle12c

Update the first 10000 rows, then the next 10000 and so on?


My table has close to 8 million rows. Is there a way to update first 10000 records and then the next 10000 records and so on.. till the 8 millionth record separately in Oracle?

I did check here for Select statement. But didn't find any solutions for an Update statement. Can someone please help? Hope this would help someone in need in the future.

UPDATE: Database version : 12C


Solution

  • This is a simple solution if you know which records has already been updated. At least it will keep your transactions within a reasonable size.

    DECLARE
        i number := 1;
    BEGIN
        while i > 0 loop
          UPDATE < your table >
             SET col = <value>
             WHERE rownum < 100000
               AND <some statement that exclude already updated records>
          i := sql%rowcount;
          commit;
        end loop;
    END;