[英]No_data_found exception is propagating to outer block also?
In my code i am entering the salary which is not available in employees table and then again inserting duplicate employee_id in primary key column of employee table in exception block where i am handling no data found exception but i do not why No data found
exception in the end also? 在我的代码我正在进入的工资是不是在员工表中可用,然后重新插入在employee表的主键列重复雇员标识异常块我在哪里处理任何数据发现异常,但我不为什么
No data found
异常的结还?
OUTPUT coming: 输出即将到来:
Enter some other sal
ORA-01400: cannot insert NULL into ("SCOTT"."EMPLOYEES"."LAST_NAME")
ORA-01403: no data found --This should not come according to logic
This is the code: 这是代码:
DECLARE
v_sal number:=&p_sal;
v_num number;
BEGIN
BEGIN
select salary INTO v_num from employees where salary=v_sal;
EXCEPTION
WHEN no_data_found THEN
DBMS_OUTPUT.PUT_LINE('Enter some other sal');
INSERT INTO employees (employee_id)values(100) ;
END;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE(sqlerrm);
END;
The behaviour is that errors hurled in the EXCEPTIONS block get concatenated to SQLERRM, and hence propagated upwards. 行为是,在EXCEPTIONS块中引发的错误被串联到SQLERRM,因此向上传播。 I grant you it is not documented but we can clearly see it here:
我同意你没有记载,但我们可以在这里清楚地看到它:
SQL> declare
2 v_sal t23.sal%type := 230;
3 l_num t23.sal%type;
4 begin
5 begin
6 begin
7 select sal into l_num
8 from t23 where sal = v_sal;
9 exception
10 when no_data_found then
11 dbms_output.put_line('inner exception::'||sqlerrm);
12 insert into t23 values (99, 'MR KNOX', v_sal);
13 end;
14 exception
15 when dup_val_on_index then
16 dbms_output.put_line('middle exception::'||sqlerrm);
17 insert into t23 (id, sal) values (99, v_sal);
18 end;
19 exception
20 when others then
21 dbms_output.put_line('outer exception::'||sqlerrm);
22 end;
23 /
inner exception::ORA-01403: no data found
middle exception::ORA-00001: unique constraint (APC.T23_PK) violated
ORA-01403: no data found
outer exception::ORA-01400: cannot insert NULL into ("APC"."T23"."LAST_NAME")
ORA-00001: unique constraint (APC.T23_PK) violated
ORA-01403: no data found
PL/SQL procedure successfully completed.
SQL>
Note: if there is a nested exception block which successfully handles the thrown exception it is not concatenated to SQLERRM. 注意:如果有一个嵌套的异常块可以成功处理引发的异常,则该异常块不会连接到SQLERRM。 That is, the SQLERRM consists of a stack of unsucessfully handled exceptions.
也就是说,SQLERRM由未成功处理的异常堆栈组成。
In your exception block you try to insert into employees
, but do not set the column last_name
, which is not NULL
-able. 在您的异常块中,您尝试插入
employees
,但不要设置last_name
列,该列不可为NULL
。
ORA-01400: cannot insert NULL into ("SCOTT"."EMPLOYEES"."LAST_NAME")
ORA-01400:无法将NULL插入(“ SCOTT”。“ EMPLOYEES”。“ LAST_NAME”)
The ORA-01403: no data found
is part of the stack-trace, caused by your failed select. ORA-01403: no data found
是堆栈跟踪的一部分,这是由您的选择失败引起的。
You can either define DEFAULT
values for all not-nullable columns or change your insert: 您可以为所有不可为空的列定义
DEFAULT
值,也可以更改插入内容:
INSERT INTO employees (employee_id, last_name, ...) Values (100, 'Scott', ...);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.