Skip to Main Content
  • Questions
  • how to find out error in biglines of procedure

Breadcrumb

Question and Answer

Chris Saxon

Thanks for the question, ma.

Asked: March 09, 2016 - 12:07 pm UTC

Last updated: March 10, 2016 - 12:15 pm UTC

Version: 12c

Viewed 1000+ times

You Asked

hi tom this naidu
i have 5000 line of code in procedure how to find out on which line we got error
plz help

and Chris said...

It's given in the exception?

SQL> create or replace procedure p as
  2  begin
  3    null;
  4    raise no_data_found;
  5  end;
  6  /

Procedure created.

SQL>
SQL> exec p;
BEGIN p; END;

*
ERROR at line 1:
ORA-01403: no data found
ORA-06512: at "CHRIS.P", line 4
ORA-06512: at line 1


Of course, if you've been trapping and re-raising the exceptions you'll lose the original line number:

SQL> create or replace procedure p as
  2  begin
  3    null;
  4    raise no_data_found;
  5  exception
  6    when no_data_found then
  7       raise;
  8  end;
  9  /

Procedure created.

SQL>
SQL> exec p;
BEGIN p; END;

*
ERROR at line 1:
ORA-01403: no data found
ORA-06512: at "CHRIS.P", line 7
ORA-06512: at line 1


In 12c you can use utl_call_stack to get information about where it was actually raised:

SQL> create or replace procedure p as
  2  begin
  3    null;
  4    raise no_data_found;
  5  exception
  6    when no_data_found then
  7      dbms_output.put_line(
  8        utl_call_stack.backtrace_unit ( utl_call_stack.error_depth ) || ' line ' ||
  9        utl_call_stack.backtrace_line ( utl_call_stack.error_depth )
 10      );
 11      raise;
 12  end;
 13  /

Procedure created.

SQL>
SQL> exec p;
CHRIS.P line 4
BEGIN p; END;

*
ERROR at line 1:
ORA-01403: no data found
ORA-06512: at "CHRIS.P", line 11
ORA-06512: at line 1


For further reading, see:

http://www.oracle.com/technetwork/issue-archive/2014/14-jan/o14plsql-2045346.html

Rating

  (2 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

And if you are not yet running Oracle Database 12c

Steven Feuerstein, March 10, 2016 - 11:16 am UTC

I just want to make sure readers don't think that you have to be on 12.1 or higher to see the backtrace information. You can always use the DBMS_UTILITY function (and it takes just one subprogram call!):

CREATE OR REPLACE PROCEDURE my_proc
AS
BEGIN
NULL;
RAISE NO_DATA_FOUND;
EXCEPTION
WHEN NO_DATA_FOUND
THEN
DBMS_OUTPUT.put_line (DBMS_UTILITY.format_error_backtrace);
RAISE;
END;
/

BEGIN my_proc; END;
/
Chris Saxon
March 10, 2016 - 12:15 pm UTC

Who was that visitor to AskTom :-)

https://youtu.be/N9-o-YDcq6I?t=46

Steven Feuerstein plsql column - online :

Rajeshwaran, Jeyabal, March 10, 2016 - 3:04 pm UTC

http://www.oracle.com/technetwork/issue-archive/2011/11-jan/o25plsql-093886.html

Steven - Read that many times, and it summarizes clearly the dbms_utility.format_error_stack and dbms_utility.format_error_backtrace with neat examples. Thanks.

More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library