开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜