Is there a way to get the line number where an exception was thrown?

Viewed 51377

Im working on a pl-sql script, in which I have about 10 TO_CHAR conversions.

One of them is throwing an

ORA-06502: PL/SQL: numeric or value error: character string buffer too small

exception.

Currently, im logging the message with this piece of code

EXCEPTION
  WHEN OTHERS THEN
    DBMS_OUTPUT.put_line('Exception message is '||SQLERRM(sqlcode));
    ROLLBACK;

I'd like to add (mostly for debugging purposes) the line where the exception is thrown, in order to receive a message in the form of

ORA-06502: PL/SQL: numeric or value error: character string buffer too small (at line x)

Is there an easy way to do this?

6 Answers

EXCEPTION
  WHEN OTHERS
  THEN
   p_err_msg := SUBSTR((SQLCODE || ' ' || SQLERRM || ' ' || dbms_utility.format_error_backtrace()),    1, 2000);

Related