【问题标题】:In oracle,does a stored procedure fail to execute further, if another stored procedure (being called inside the first procedure) fails在 oracle 中,如果另一个存储过程(在第一个过程中被调用)失败,存储过程是否无法进一步执行
【发布时间】:2019-01-30 14:14:36
【问题描述】:
有两个存储过程 - proc_outer() 和 proc_inner()。 proc_inner() 正在通过 proc_outer() 调用,如下所示 -
create procedure proc_outer() as
-- some statements
Begin
-- some statements
proc_inner();
-- update statements;
End proc_outer;
/
所以问题是 - 如果 proc_inner() 由于运行时异常而失败,proc_outer 也会失败还是 proc_outer 会继续执行更新语句?
【问题讨论】:
标签:
oracle
stored-procedures
plsql
oracle11g
【解决方案1】:
它会失败。看看这个例子:
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”。