Q
Problem solve Get help with specific problems with your technologies, process and projects.

Resolving error ORA-01002

I am trying to run C++ code with imbedded ProC. When it gets to the point of 'EXEC SQL declare <cursorname> for <stmtname>, it returns with an ORA-01002: fetch out of sequence Error Message. It's always worked in the past. I hope you can help. Let me know if you need any further information.

It seems like a fetch has been attempted in your code from the cursor when the cursor is no longer valid. A PL/SQL cursor loop implicitly does fetches and can cause this error.

1) Are you fetching from the cursor even after the last row is retrieved and ORA 1403 error is returned? If that is the case, do not issue a fetch after the last row is retrieved.

2) Is the cursor opened with the FOR UPDATE clause? If so, then if a COMMIT statement is inside the loop, fetching after the commit may return the error. Do not issue a COMMIT inside the fetch loop.

3) Are you rebinding any placeholder variables? Then issuing a fetch before re-executing the statement can return the error. So, what you need to do in that case is, re-execute again after rebinding AND then fetch.


Dig Deeper on Using Oracle PL-SQL

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchDataManagement

SearchBusinessAnalytics

SearchSAP

SearchSQLServer

TheServerSide.com

SearchDataCenter

SearchContentManagement

SearchHRSoftware

Close