Error in fetching from cursor using Oracle Pro*C
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.
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.
精彩评论