问题
Usually when I declare a cursor with a query which fetches no records:
EXEC SQL Declare abcd Cursor For Select 'A' abc from dual where 1=2
the return sqlca.sqlcode is 0.
So I have a cursor in a function which is being called multiple times. Sometimes it fetches records & sometimes it doesn't depending on the process phase, however in certain cases the declare cursor is throwing the below error & in most of the cases it passes successfully:
Code [1403], Error Message: [ORA-01403: no data found]
Function workflow()
{
declare cursor
open cursor
for(;;)
{
fetch into x
if(sqlca.sqlcode != 0)
break;
update using x
}
close cursor;
commit;
}
Can someone please advise, why sometimes I am getting No-Data-Found. Is something wrong in my workflow.
回答1:
After a lot of R & D [basically lots of printf's] i finally figured out the bug....
declare cursor doesn't change/return sqlca.sqlcode.
IDK how it works internally however from my testing program i figured that the 1403 is coming from another query before the declare cursor & declare cursor is not returning/changing sqlca.sqlcode the 1403 persists & causes the error.
Would really like if someone could explain how declare works & why it doesn't return/manipulate sqlca.sqlcode.
来源:https://stackoverflow.com/questions/47094110/strange-cursor-behavior-while-declaring-same-cursor-multiple-times