|ora-010002 fetch out of sequence. [message #202317]
||Thu, 09 November 2006 01:57
Registered: November 2006
I have stuck up with a problem. The problem is that i am getting fetch out of sequence(ORA-01002) sql exception.
This error is occurring when i am trying to get the resultset object from the ref cursor. By using the following code
stmt = conn.prepareCall(procedure(?,?));
Actually in the procedure i am just opening the cursor and using select statement. I am not using any update statements or
So in my case this 'fetch out of sequence' is occuring when a fetch is attempted against a cursor that is no longer valid. As our code is ignoring any and all exceptions. And our calling code still attempts to fetch from the cursor.
Previous code for handling exceptionException
When others THEN
So if we rewrite the code for handling the exception like the below means will it solve the problem or not.
WHEN OTHERS THEN
err_code := SQLCODE;
err_msg := substr(SQLERRM, 1, 200);
INSERT INTO tt_audit_table (procedure_name, load_date, error_number, error_message)
VALUES ('get_dispatch_tasks', sysdate, err_code, err_msg);
If you think this is not the right approach means can you please suggest the right approach.So that i can escape this exception in future.By handling it in the pl/sql package level.
thanks in advance.
|Re: ora-010002 fetch out of sequence. [message #202406 is a reply to message #202317]
||Thu, 09 November 2006 10:47
Registered: March 2000
you need to make sure that your code is using the same connection from the time it opens the cursor until it retrieves the last row. Aslo - make sure that the ODBC connection (or whatever you're using doesn't have any kind of autocommit enabled.|
If you start a sql trace before you open the resultset and turn it off again retrieving it, you'll be able to count the commits in the trace file to confirm what's happening.
execute immediate 'alter session set tracefile_identifier = ''TEST''';
-- trace file directory
WHERE NAME = 'user_dump_dest';
then just look in that location for your trace file(s) *_TEST.trc
This script is from oramag in 2000
# Script to calculate # of commits and rollbacks from a trace file
# Takes trace file as input
# XCTEND rlbk=%d rd_only=%d
# XCTEND A transaction end marker.
# rlbk 1 if a rollback was performed, 0 if no rollback (commit).
# rd_only 1 if transaction was read only, 0 if changes occurred.
grep XCTEND $1 > /tmp/read.lst
commit=`grep XCTEND /tmp/read.lst | grep "rlbk=0, rd_only=0" | wc -l`
trans=`grep XCTEND /tmp/read.lst | wc -l`
rollback=`grep XCTEND /tmp/read.lst | grep "rlbk=1, rd_only=0" | wc -l`
echo " "
echo "Transaction Ends $trans"
echo "Real Commits $commit"
echo "Rollbacks $rollback"
to trap debug messages, use an autonomous transaction.
CREATE OR REPLACE PROCEDURE put_debug_sql (i_seq IN INTEGER, i_msg VARCHAR)
INSERT INTO DEBUG_SQL
VALUES (i_seq, SYSDATE, i_msg);
WHEN OTHERS THEN
put_debug_sql (123, SQLERRM);