Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 896
Revious Avatar asked Aug 11 '11 20:08

Revious


People also ask

How do I find the package name in Oracle?

You can use the USER_PROCEDURES view as it contains the package name in the OBJECT_NAME column and procedure within it in the PROCEDURE_NAME column for records having OBJECT_TYPE = 'PACKAGE' .

How do I view packages in PL SQL Developer?

Go to VIEW menu, click on find DB objects option. In the find db object pane put the name of the package and select the DB. Both, the spec and body will appear, double click to open.

Which package is used to obtain information about PL SQL?

Oracle Database PL/SQL Packages and Types Reference for information about the many product-specific packages that Oracle Database supplies.


2 Answers

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. 
like image 186
Justin Cave Avatar answered Sep 19 '22 15:09

Justin Cave


Or try DBMS_UTILITY.FORMAT_CALL_STACK

like image 43
xmedeko Avatar answered Sep 20 '22 15:09

xmedeko