ORA-01002: fetch out of sequence [message #398597] |
Thu, 16 April 2009 20:58 |
oracle123
Messages: 56 Registered: March 2009
|
Member |
|
|
Hi all,
I am back with one more issue. I am fetching records through a cursor from database using Pro*C and inserting some records as shown below:
EXEC SQL DECLARE cur_num CURSOR FOR
SELECT STUDENT_NUMBER
FROM STUDENTS
WHERE STDID = :temp_num
ORDER BY STUDENT_NUMBER;
EXEC SQL OPEN cur_num;
EXEC SQL WHENEVER NOT FOUND DO break;
EXEC SQL WHENEVER SQLERROR DO sqlerror();
for(;;)
{
EXEC SQL FETCH cur_num INTO :std_num ;
/* Some calculations here */
EXEC SQL INSERT INTO RESULTS(STUDENT_NUMBER,
SUBJECT,
MARKS)
VALUES(:std_num,
:sub,
:marks);
EXEC SQL COMMIT;
}
EXEC SQL CLOSE cur_num;
This code works fine sometimes but ends up with this error sometimes:
ORA-01002: fetch out of sequence
and also do I need to do null termination once i fetch data from the database like this:
Quote: | EXEC SQL FETCH cur_num INTO :std_num ;
std_num.arr[std_num.len] = '\0';
|
std_num is declared as varchar datatype.
Thanks,
Scott.
|
|
|
|
|
|
Re: ORA-01002: fetch out of sequence [message #398794 is a reply to message #398597] |
Fri, 17 April 2009 10:33 |
oracle123
Messages: 56 Registered: March 2009
|
Member |
|
|
Michel,
Here is my compilation option:
Quote: | proc mode=?
Pro*C/C++: Release 10.2.0.4.0 - Production on Fri Apr 17 10:21:20 2009
Copyright (c) 1982, 2007, Oracle. All rights reserved.
System default option values taken from: /oracle_client/product/v10r2/precomp/admin/pcscfg.cfg
Option name : mode=string
Current value : oracle
Restrictions : ansi, iso, oracle
Description : Code conformance to Oracle or ANSI rules
PCC-F-02135, CMD-LINE: User asked for help
|
Still I wonder why it is giving me that error. Please help. I am sincerely greatful for your prompt responses in these forums.
Thanks,
Scott.
|
|
|
|
Re: ORA-01002: fetch out of sequence [message #398823 is a reply to message #398597] |
Fri, 17 April 2009 15:44 |
oracle123
Messages: 56 Registered: March 2009
|
Member |
|
|
Michel,
Lets suppose I have 100 records to insert into the database through that loop.
So if I commit after the loop and if there is an oracle error while inserting 50th record, how does it handle it?
Is it going to insert rest of the 99 records or else undo everything.
Thanks,
Scott.
|
|
|
|
|