pl/sql中的异常处理

Nir*_*bey 6 oracle plsql

我有一个存储过程

create or replace procedure Trial
    is 
Begin
---Block A--
EXCEPTION
when others then
insert into error_log values('error');
--Block A ends----
--Block B ----
----Block B ends---
end;
Run Code Online (Sandbox Code Playgroud)

我希望块B中的代码在所有条件下执行,即如果块A中的异常是否被引发.使用上面的代码,块B仅在引发异常时执行.这该怎么做.请帮忙.

Ton*_*ews 7

您可以创建嵌套块:

create or replace procedure Trial
    is 
Begin
  begin
    ---Block A--
  EXCEPTION
    when others then
      insert into error_log values('error');
  end;
  begin
    --Block B ----
  end;
end;
Run Code Online (Sandbox Code Playgroud)

  • 您实际上并不需要块 B 周围的“开始”/“结束”,但它们可能会在这种情况下增加清晰度。 (2认同)