2

I'm converting an ingres C program to Oracle Pro*C.

I create and open a cursor to do a SELECT (not a SELECT FOR UPDATE).

The existing program does (roughly)

EXEC SQL DECLARE N CURSOR for SELECT...
EXEC SQL OPEN N
EXEC SQL FETCH N INTO :new
while (sqlca.sqlcode != 100) {
  // process the contents of :new
  EXEC SQL FETCH N INTO :new
}
EXEC SQL CLOSE N;

When I reach the last line returned by the select statement, I get an error, ORA-01002: fetch out of sequence.

I don't want to put my cleanup code in my error handler; I would rather that the loop exit cleanly.

1
  • Solved it myself -- see below -- just wanted to capture it here in case this happens to anybody else. Commented Aug 3, 2011 at 19:37

1 Answer 1

3

In fact, careful analysis (by which I mean "tons of printf()s") indicates that sqlca.sqlcode is never anything other than null until the loop is complete.

So I just changed the condition on the loop to be

while (sqlca.sqlcode =='\0') 

rather than

while (sqlca.sqlcode != 100)

And all is well.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.