Error Line Number In Oracle
Contents |
TECHNOLOGY: PL/SQL Tracing Lines By Steven Feuerstein Find and report your errors—by line number—in Oracle Database 10g. PL/SQL offers a powerful and flexible exception architecture. Of course, there is always room for improvement, and in Oracle Database 10g, how to find error line number in pl/sql exception handling takes a big step forward with the introduction of the DBMS_UTILITY.FORMAT_ERROR_BACKTRACE function. dbms utility format error backtrace This article explores the problem that this function solves and how best to use it. Who Raised That Exception? When an exception
Oracle Sqlerrm
is raised, one of the most important pieces of information a programmer would like to uncover is the line of code that raised the exception. Prior to Oracle Database 10g, one could obtain this information
Oracle Error Line Number Wrong
only by allowing the exception to go unhandled. Let's revisit the error-handling behavior available to programmers in Oracle9i Database. Consider this simple chain of program calls in Listing 1: procedure proc3 calls proc2 calls proc1 , at which point proc1 raises the NO_DATA_FOUND exception. Notice that there is no error handling in any of the procedures; it is most significantly lacking in the top-level proc3 procedure. If I run proc3 in SQL*Plus, oracle exception line number I will see the following results: ERROR at line 1: ORA-01403: no data found ORA-06512: at "SCOTT.PROC1", line 4 ORA-06512: at "SCOTT.PROC2", line 6 ORA-06512: at "SCOTT.PROC3", line 4 ORA-06512: at line 3 Code Listing 1: A stack of procedures CREATE OR REPLACE PROCEDURE proc1 IS BEGIN DBMS_OUTPUT.put_line ('running proc1'); RAISE NO_DATA_FOUND; END; / CREATE OR REPLACE PROCEDURE proc2 IS l_str VARCHAR2(30) := 'calling proc1'; BEGIN DBMS_OUTPUT.put_line (l_str); proc1; END; / CREATE OR REPLACE PROCEDURE proc3 IS BEGIN DBMS_OUTPUT.put_line ('calling proc2'); proc2; END; / This is the error trace dump of an unhandled exception, and it shows that the error was raised on line 4 of proc1. On the one hand, we should be very pleased with this behavior. Now that we have the line number, we can zoom right in on the problem code and fix it. On the other hand, we got this information by letting the exception go unhandled. In many applications, however, we work to avoid unhandled exceptions. Let's see what happens when I add an exception section to the proc3 procedure and then display the error information (the simplest form of error logging). Here is the second version of proc3 : CREATE OR REPLACE PROCEDURE proc3 IS BEGIN DBMS_OUTPUT.put_line ('calling proc2'); proc2; EXCEPTION WHEN OTHERS THEN my_putline ( DBMS_UTILITY.FORMAT_ER
E-mail to friend How to get Error Line Number in PL/SQL in Exception Block [message #325159] Thu, 05 June 2008 03:17 rajatratewal Messages: 507Registered: March 2008 Location: INDIA Senior Member When we use exception block in pl/sql and use SQLERRM it displays only the error
Exception No Data Found Oracle
details but not the exact line number where error has occured. But if we don't use dbms_utility.format_error_backtrace example in oracle exception block line number is also displayed. How to get Error Line Number in pl/sql exception block. Is their any method to achieve this in what are the methods there in save exceptions in oracle 9i. 10g we have DBMS_UTILITY Backtrace procedure to achieve this. Any ideas?? Report message to a moderator Re: How to get Error Line Number in PL/SQL in Exception Block [message #325173 is a reply to message #325159] http://www.oracle.com/technetwork/testcontent/o25plsql-093886.html Thu, 05 June 2008 04:26 Michel Cadot Messages: 63863Registered: March 2007 Location: Nanterre, France, http://... Senior MemberAccount Moderator Of course, the first question should be why do you use sqlerrm? "When others then dbms_output.put_line(sqlerrm)"? Regards Michel [Updated on: Thu, 05 June 2008 04:30]Report message to a moderator Re: How to get Error Line Number in PL/SQL in Exception Block [message #325182 is a reply to message #325173] Thu, 05 June 2008 04:38 rajatratewal Messages: 507Registered: March 2008 Location: INDIA http://www.orafaq.com/forum/t/119924 Senior Member Yes you are right Michel I am using it with others clause. I can replace it with built in or custom exceptions like NO_DATA_FOUND etc. But my question is How to get the Error line number that is causing the exception to throw. If we run a pl/sql procedure without exception block then in Sql* plus we can see the line number where error has occured. If our procedure is small it is very easy to check the statement that is causing error.But if it is quite large then it is not possible to check every line in debug mode.because in b/w begin and end clause we can have number of statements and one exception block to handle all the exceptions. Is their any method available in oracle 9i by which i can trace the statement that has caused the exception to throw. Report message to a moderator Re: How to get Error Line Number in PL/SQL in Exception Block [message #325185 is a reply to message #325182] Thu, 05 June 2008 04:44 Michel Cadot Messages: 63863Registered: March 2007 Location: Nanterre, France, http://... Senior MemberAccount Moderator Quote:But my question is How to get the Error line number that is causing the exception to throw. Just remove "when others" Regards Michel Report message to a moderator Re: How to get Error Line Number in PL/SQL in Exception Block [message #325192 is a reply to message
than it can show what exception was raised.We will never know in which http://kaamka.blogspot.com/2011/05/error-line-number-in-plsql-procedure.html line exception was thrown.Best approach will be to use http://www.praetoriate.com/t_high_perform_line_numbers.htm combination of SQLERRM and DBMS_UTILITY.FORMAT_ERROR_BACKTRACE()Example : If we are calling many functions in single PL/SQL block then we it will give us the exact trace of exception with line number.ORA-06512: at "ABC.XYZ_PROC", line 7056 example --> DECLARE vr_sqlerrm line number VARCHAR2(1000):=null; BEGIN ----some code here EXCEPTION WHEN OTHERS THEN vr_sqlerrm := SUBSTR( SQLERRM||DBMS_UTILITY.FORMAT_ERROR_BACKTRACE(),0,999); raise_application_error(-20003,EXCEPTION is --> 'vr_sqlerrm); END; Posted by amardeep at 11:47 PM Labels: DBMS_UTILITY.FORMAT_ERROR_BACKTRACE, exact line number, tracking exceptions in oracle 10g No comments: Post a error line number Comment Newer Post Older Post Home Subscribe to: Post Comments (Atom) Followers Total Pageviews About Me amardeep View my complete profile Blog Archive ► 2016 (8) ► September (8) ► 2014 (1) ► July (1) ► 2013 (1) ► August (1) ► 2012 (1) ► May (1) ▼ 2011 (10) ▼ May (10) calculate size of folder in linux Regular Expression for no special character Regular expression in PL/SQL TATA PHOTON + on Ubuntu 10.04 (Lucid Lynx) enable profiler in JDeveloper run jvm in 64 bit mode Java GC (garbage collection) logs analysis Java Thread dump analysis Print bar code in xslt Error line number in PL/SQL procedure. ► 2009 (24) ► September (6) ► July (1) ► June (3) ► May (1) ► April (4) ► March (1) ► February (1) ► January (7) Simple template. Powered by Blogger.
position number. SQL*Plus skips over blank lines when compiling code, so you’ll need to determine the line of code to which the line number refers. This is done by using the list command, as shown in Figure 8.4. Figure 8.4Using the list command to find a line of code. If you like, you can also use the list command to display a range of lines. For example, list 10 15 displays lines 10 through 15 of your source code. If you specify just one line number, list will only display that line. For instance, list 10 displays only line 10 of your code. Using the list command without specifying a line number instructs SQL*Plus to display the entire contents of the buffer. When The Line Number Is Wrong Oracle reports the line number on which an error is detected. It’s not uncommon for the reported line number to be incorrect, because you’ve done something else incorrectly in your code that has no effect until Oracle tries to compile the line number specified in the output of the show errors command. Most of the time, incorrect line numbers are the result of variable and type declaration problems, or as a result of incorrect references to objects or variables. Consider again the code for the Calculate_Student_Grades() procedure, presented in Listing 8.4. Listing 8.4 The Calculate_Student_Grades() procedure. CREATE OR REPLACE PROCEDURE Calculate_Student_Grades IS CURSOR Active_Students_cur IS SELECT ssn FROM STUDENTS WHERE graduation_date IS NOT NULL; Active_Student_rec Active_Students_cur%ROWTYPE; vCurrentSSN STUDENTS.ssn%ROWTYPE; nNewGPA STUDENTS.gpa%TYPE; BEGIN FOR Active_Student_rec IN Active_Student_cur LOOP nNewGPA := Calculate_GPA (vSSN => vCurrentSSN); END LOOP; END Calculate_Student_Grades; / Attempting to compile this code generates three errors. The line and position numbers of these errors are shown in Table 8.1. Table 8.1 Compile errors for the Calculate_Student_Grades() procedure. Line Number Position Error 9 31 PLS-00310: with %ROWTYPE attribute, ‘STUDENTS.SSN’ must name a table, cursor or cursor-variable 10 40 PLS-00302: component ‘GPA’ must be declared 12 30 PLS-00201: identifier ‘ACTIVE_STUDENT_CUR’ must be declared Running the list command against line 12 of the code for the procedure shows that the error occurred at the BEGIN statement. This isn’t really the case. The real cause of the error is the reference on line 13 to