How to re-raise pl/sql exception in exception handling block?

半城伤御伤魂 提交于 2020-01-02 00:13:31

问题


I have the following procedure which is used by some applications:

procedure p1
is
begin
  bla bla bla;  
end;

But there is no exception handling block. So applications were written according this feature.

Now I need to log errors in p1. But it shouldn't affect applications that use this procedure.

Something like this:

procedure p1
is
begin
  bla bla bla;

  exception when others then
    log_error(sqlcode, sqlerrm);
    raise_new_exception (sqlcode, sqlerrm);
end;

In case of raise_application_error first parameter should be in range [-20000, -20999]. So if there raises exception no_data_found, it cannot raise this error.

In case of exception_init, second parameter should not be variable. It must be numeric literal.

PS: As temporary solution, I'm using execute immediate


回答1:


If your error stays the same, change to

...
exception when others then
  log_error(sqlcode, sqlerrm);
  raise;
end;
/

This is explained in the documentation.



来源:https://stackoverflow.com/questions/14978431/how-to-re-raise-pl-sql-exception-in-exception-handling-block

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!