Oracle-与过程相关的查询 [英] Oracle - procedure related query
问题描述
我在oracle中编写以下查询:
I am writing the below queries in oracle:
DBMS_OUTPUT .....'Ashish'
DBMS_OUTPUT.....'Ashish'
从tab_1到val1中选择col1
Select col1 into val1 from tab_1
DBMS_OUTPUT .....'Ubale'
DBMS_OUTPUT.....'Ubale'
当我运行此过程时,我只能以"Ashish"的形式得到输出,为什么? 还有v_val1变量的值
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
推荐答案
由于表为空,因此"select into"语句将引发NO_DATA_FOUND异常.这就是为什么您没有收到第二条消息的原因. val1将具有与select之前相同的值-即如果您之前未分配值,则为null.
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.
您不知道自己遇到了NO_DATA_FOUND异常,这一事实表明您犯了PL/SQL开发人员有史以来最大的错误之一:
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;
这篇关于Oracle-与过程相关的查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!