Strange Cursor behavior while declaring same cursor multiple times

浪子不回头ぞ 提交于 2019-12-11 16:05:42

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!