PLSQL将失败传递回执行任务



我在oracle中有一个运行plsql代码的计划作业。我希望能够将预定的作业标记为失败,如果计划发生在代码内,但我已经失败了我的谷歌搜索技能。

if a = b then
return (and get the code to fail)
end if;

我假设我错过了一些非常明显的东西,但在任何地方都找不到它。

感谢

也许这将有助于演示:

SQL> set serverout on
SQL> --
SQL> create or replace procedure my_proc(p_value number)
2  as
3  ex_custom1 exception;
4  pragma exception_init(ex_custom1,-20001);
5  ex_custom2 exception;
6  pragma exception_init(ex_custom2,-20002);
7  begin
8    if p_value = 1
9      then raise_application_error (-20001,'This is custom error 1');
10    end if;
11  --
12    if p_value = 2
13      then raise_application_error (-20002,'This is custom error 2');
14    end if;
15  --
16    dbms_output.put_line('Non-error completion');
17  exception
18    when ex_custom1
19    then
20      dbms_output.put_line( sqlerrm );
21
22    when ex_custom2
23    then
24      dbms_output.put_line( sqlerrm );
25  end;
26  /
Procedure created.
SQL> show errors
No errors.
SQL> --
SQL> exec my_proc(1);
ORA-20001: This is custom error 1
PL/SQL procedure successfully completed.
SQL> exec my_proc(2);
ORA-20002: This is custom error 2
PL/SQL procedure successfully completed.
SQL> exec my_proc(3);
Non-error completion
PL/SQL procedure successfully completed.
SQL>
SQL>
SQL>
SQL> --
SQL> drop procedure my_proc;
Procedure dropped.
SQL> --
SQL> spo off
~

最新更新