Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: PL/SQL Question
In article <8c4dvu$vl6$1_at_nnrp1.deja.com>,
amerar_at_unsu.com wrote:
>
>
> Hi there,
>
> I have a cursor FOR loop that will update over 1 million records. The
cursor
> is defined with the FOR UPDATE clause. I have a counter that
commits after
> every 10000, however when running the program I got this error:
>
> ORA-01002: Fetch out of sequence
>
> What does this mean? Can't I commit within a cursor FOR loop?
>
In general -- you can commit in a cursor for loop (its a bad practice
and can lead to other errors - in particular ORA-1555 if you are
updating the table you are selecting from).
In particular though -- a commit closes all FOR UPDATE queries though.
A commit releases the locks you have aquired. A select for update gets
lots of locks. They are released when you commit -- hence the query
must close. So, you cannot commit in a cursor for loop that has a for
update.
Selecting for update 1,000,000 rows is *extremely* expensive. The
select for update will take a long time to open. Consider locking the
table or just locking the rows you will actually process in the update.
For example, lets say you are going to do 1million out of 5million
records. There is a "needs_processing" field in the record you set to
Y before processing this record. After processing it is set to NULL.
You might use logic such as:
ops$tkyte_at_8i> REM drop table t;
ops$tkyte_at_8i> REM create table t as select a.*, 'Y' needs_processing
from all_objects a;
ops$tkyte_at_8i> REM create index t_idx on t(needs_processing); ops$tkyte_at_8i> set serveroutput on ops$tkyte_at_8i> declare
processing 999 records... processing 1998 records... processing 2997 records... processing 3996 records... processing 4995 records... processing 5994 records... processing 6993 records... processing 7992 records... processing 8991 records... processing 9990 records... processing 10989 records... processing 11988 records... processing 12987 records... processing 13986 records... processing 14985 records... processing 15984 records... processing 16983 records... processing 17982 records... processing 18981 records... processing 19980 records...
------- ---------------------------------------------------20421 FOR UPDATE
Sent via Deja.com http://www.deja.com/
Before you buy.
Received on Sat Apr 01 2000 - 07:23:25 CST
![]() |
![]() |