有两个存储过程-proc_outer()和proc_inner()。通过proc_outer()调用proc_inner(),如下所示-
create procedure proc_outer() as
-- some statements
Begin
-- some statements
proc_inner();
-- update statements;
End proc_outer;
/
所以问题是-如果proc_inner()由于运行时异常而失败,proc_outer也会失败还是proc_outer继续执行更新语句?
答案 0 :(得分:3)
它将失败。看一个例子:
SQL> set serveroutput on
SQL> create table test (col number);
Table created.
SQL> insert into test values (1);
1 row created.
SQL> create or replace procedure proc_inner as
2 l_div number;
3 begin
4 select 1/0 into l_div from dual;
5 end;
6 /
Procedure created.
SQL> create or replace procedure proc_outer as
2 l_col test.col%type;
3 begin
4 update test set col = col + 100;
5 select col into l_col from test;
6 dbms_output.put_line('some statements - l_col = ' || l_col);
7 proc_inner;
8 update test set col = col + 200;
9 select col into l_col from test;
10 dbms_output.put_line('update statements - l_col = ' || l_col);
11 end;
12 /
Procedure created.
测试:
SQL> exec proc_outer
some statements - l_col = 101
BEGIN proc_outer; END;
*
ERROR at line 1:
ORA-01476: divisor is equal to zero
ORA-06512: at "SCOTT.PROC_INNER", line 4
ORA-06512: at "SCOTT.PROC_OUTER", line 7
ORA-06512: at line 1
SQL> select * from test;
COL
----------
1
SQL>
如您所见,“某些语句”已执行,但“更新语句”未执行。
此外,即使第一个UPDATE
成功(l_col = 101
),该错误也会导致回滚,因此测试表中的最终结果是开始的“ 1
”。