Home » SQL & PL/SQL » SQL & PL/SQL » need to find exception line no inside procedure of 1000 lines. (Oracle 11G)
need to find exception line no inside procedure of 1000 lines. [message #623006] Wed, 03 September 2014 05:26 Go to next message
hemant_khandare
Messages: 72
Registered: November 2011
Member
Hi Experts,

How can i find on which line error is ,inside procedure of 1000 lines of code using exception handling.

please help

Thanks in advance
Re: need to find exception line no inside procedure of 1000 lines. [message #623008 is a reply to message #623006] Wed, 03 September 2014 05:30 Go to previous messageGo to next message
Littlefoot
Messages: 21808
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Remove EXCEPTION section and run the procedure in SQL*Plus. It'll tell you error location, such as
SQL> create or replace procedure p_test as
  2    l_deptno emp.deptno%type;
  3  begin
  4    select deptno
  5      into l_deptno
  6      from emp;
  7  end;
  8  /

Procedure created.

SQL> exec p_test;
BEGIN p_test; END;

*
ERROR at line 1:
ORA-01422: exact fetch returns more than requested number of rows
ORA-06512: at "SCOTT.P_TEST", line 4                                      --> here!
ORA-06512: at line 1


SQL>
Re: need to find exception line no inside procedure of 1000 lines. [message #623011 is a reply to message #623008] Wed, 03 September 2014 05:55 Go to previous messageGo to next message
hemant_khandare
Messages: 72
Registered: November 2011
Member
Thanks
Re: need to find exception line no inside procedure of 1000 lines. [message #623016 is a reply to message #623011] Wed, 03 September 2014 06:40 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

But of course it works only if you don't use WHEN OTHERS.

Re: need to find exception line no inside procedure of 1000 lines. [message #623018 is a reply to message #623016] Wed, 03 September 2014 06:44 Go to previous messageGo to next message
Littlefoot
Messages: 21808
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
That's why I told him to remove exception section (whichever he might be using).
Re: need to find exception line no inside procedure of 1000 lines. [message #623020 is a reply to message #623006] Wed, 03 September 2014 06:46 Go to previous messageGo to next message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
hemant_khandare wrote on Wed, 03 September 2014 15:56
using exception handling.


If you have an exception handling, you can add dbms_utility.format_error_stack and dbms_utility.format_error_backtrace :

SQL> set serveroutput on;
SQL> CREATE OR replace PROCEDURE P_test
  2  AS
  3    l_deptno emp.deptno%TYPE;
  4  BEGIN
  5      SELECT deptno
  6      INTO   l_deptno
  7      FROM   emp;
  8  EXCEPTION
  9    WHEN OTHERS THEN
 10               dbms_output.Put_line ('---------------------');
 11
 12               dbms_output.Put (dbms_utility.format_error_stack);
 13
 14               dbms_output.Put (dbms_utility.format_error_backtrace);
 15
 16               dbms_output.Put_line ('---------------------');
 17
 18               RAISE;
 19  END;
 20
 21  /

Procedure created.

SQL> sho err;
No errors.
SQL> exec p_test;
---------------------
ORA-01422: exact fetch returns more than requested number of rows
ORA-06512: at
"SCOTT.P_TEST", line 5
---------------------
BEGIN p_test; END;

*
ERROR at line 1:
ORA-01422: exact fetch returns more than requested number of rows
ORA-06512: at "SCOTT.P_TEST", line 18
ORA-06512: at line 1

SQL>


But you shoould NOT have dbms_output in production code, so you need to log these errors in an error logging table.


Regards,
Lalit
Re: need to find exception line no inside procedure of 1000 lines. [message #623021 is a reply to message #623018] Wed, 03 September 2014 06:47 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Just wanted to put the link to the wiki article.

Re: need to find exception line no inside procedure of 1000 lines. [message #623145 is a reply to message #623021] Fri, 05 September 2014 03:57 Go to previous messageGo to next message
hemant_khandare
Messages: 72
Registered: November 2011
Member
Thanks but why you used raise in others exception??

Is there any other way to get error line no using exception handling mechanism??
Re: need to find exception line no inside procedure of 1000 lines. [message #623153 is a reply to message #623145] Fri, 05 September 2014 04:16 Go to previous message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
I deleted your duplicate message.

hemant_khandare wrote on Fri, 05 September 2014 14:27
Thanks but why you used raise in others exception??


I have used RAISE to re-raise the error and that's what you need to do in order to propagate the error back to client. But, see how line number is changed and now it shows that of RAISE.

*
ERROR at line 1:
ORA-01422: exact fetch returns more than requested number of rows
ORA-06512: at "SCOTT.P_TEST", line 18                                 --> this is still wrong line number of error
ORA-06512: at line 1



Quote:
Is there any other way to get error line no using exception handling mechanism??

Did you properly see what i explained above? There are two things in BOLD in my previous post. Read again.
Previous Topic: Recover rows after delete and commit
Next Topic: Round values to 0,5,10,100 ..
Goto Forum:
  


Current Time: Thu Apr 25 21:17:49 CDT 2024