Quick Search:
CODE
Oracle PL/SQL Code Library
JOBS
Find Or Post Oracle Jobs
FORUM
Oracle Discussion & Chat
 Oracle PL/SQL: Using COMMIT in a PL/SQL loop Jump to:  
Category: >> Oracle PL/SQL >> Using COMMIT in a PL/SQL loop Bookmark and Share

<< lastnext >>

Snippet Name: Using COMMIT in a PL/SQL loop

Description: Oracle recommends that you COMMIT less frequently within a PL/SQL loop to prevent ORA-1555 (Snapshot too old) errors.

The higher the frequency of commit, the sooner the extents in the undo/ rollback segments will be cleared for new transactions, causing ORA-1555 errors.

To fix this problem you can rewrite code as shown in the example.

Also see:
» Nested Loops: loop through tables

Comment: (none)

Language: PL/SQL
Highlight Mode: PLSQL
Last Modified: March 06th, 2009

-- original code, too many COMMITs
 
FOR records IN my_cursor LOOP
   ...DO something...
   COMMIT;
END LOOP;
COMMIT;
 
 
-- rewritten code that commits every 10000 records
 
FOR records IN my_cursor LOOP
   ...DO something...
   i := i+1;
   IF MOD(i, 10000) = 0 THEN    -- Commits once per 10000 records
      COMMIT;
   END IF;
END LOOP;
COMMIT;
 


Free
Oracle Magazine
Subscriptions
and Oracle White Papers


SQL University.net courses meet the most demanding needs of the business world for advanced education in a cost-effective manner. SQL University.net courses are available immediately for IT professionals and can be taken without disruption of your workplace schedule or processes.

Compared to traditional travel-based training, SQL University.net saves time and valuable corporate resources, allowing companies to do more with less. That's our mission, and that's what we deliver.

Click here to find out more
 
Home      :      Code Library      :      Sponsors      :      Privacy      :      Terms of Use      :      Contact Us 79 users online    © 2009 psoug.org

PSOUG LOGIN
Username: 
Password: 
Forgot your password?