Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to safely commit inside a cursor loop

ziggy25Mar 5 2010 — edited Mar 7 2010
Given the following example
cursor test_cursor is
 select * 
 from authors;

open test_cursor;

if (test_cursor%rowcount = 0) then
 raise no_data;
else
	close test_cursor;
	for test_cursor_rec in test_cursor
	loop
		update authors
		set id="21"
		commit;
	end loop
end if;
The above code example, selects everything into a cursor and loops through the cursor to update rows that are in the authors table. This is the same data that is on the cursor. I have been getting "snapshot too old" errors and reading about this error i concluded that the commit statement is causing this as i am making changes to the data which the cursor is using.

What is the alternative way to do this to avoid the "snapshot too old" errrors. ?

Thanks
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 4 2010
Added on Mar 5 2010
16 comments
23,966 views