Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
763 views
in Technique[技术] by (71.8m points)

exception handling - Oracle PL/SQL: how to get the stack trace, package name and procedure name

Sometimes the exception returns something like: "ORA-06502: PL/SQL: numeric or value error: character string buffer too small".

It's not so readable since it doesn't report neither the table, the column and the value it tried to write.

it would be useful to get the current procedure name at the moment the Exception happened or is catched.

How can I obtain that?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You probably want DBMS_UTILITY.FORMAT_ERROR_BACKTRACE function

SQL> ed
Wrote file afiedt.buf

  1  create or replace procedure p1
  2  is
  3  begin
  4    raise_application_error( -20001, 'Error 1', true );
  5* end;
SQL> /

Procedure created.

SQL> create or replace procedure p2
  2  as
  3  begin
  4    null;
  5    p1;
  6  end;
  7  /

Procedure created.

SQL> begin
  2    p2;
  3  exception
  4    when others then
  5      dbms_output.put_line( dbms_utility.format_error_backtrace );
  6  end;
  7  /
ORA-06512: at "SCOTT.P1", line 4
ORA-06512: at "SCOTT.P2", line 5
ORA-06512: at
line 2


PL/SQL procedure successfully completed.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...