Oracle - procedure related query

梦想与她 提交于 2019-12-25 01:55:43

问题


I am writing the below queries in oracle:

DBMS_OUTPUT.....'Ashish'

Select col1 into val1 from tab_1

DBMS_OUTPUT.....'Ubale'

when I run this procedure I get the output as "Ashish" only why? also what will be the value of v_val1 variable

Note: the table does not contain any records


回答1:


Since the table is empty, the "select into" statement will raise the NO_DATA_FOUND exception. That's why you don't get the second message. val1 will have the same value as before the select - i.e. null if you didn't previously assign a value.

The fact that you don't know you got the NO_DATA_FOUND exception suggests that you have made one of the biggest errors PL/SQL developers ever make:

EXCEPTION
    -- Never do this in real code!!!
   WHEN OTHERS THEN NULL;
END;



回答2:


Did you get error? If the table doesn't have rows in it. You might get no_data_found exception.

By the way, where is your entire code?



来源:https://stackoverflow.com/questions/1438362/oracle-procedure-related-query

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