Oracle Pl Sql Error Line Number
Contents |
CommunityOracle User Group CommunityTopliners CommunityOTN Speaker BureauJava CommunityError: You don't have JavaScript enabled. This tool uses JavaScript and much of it will not work correctly without it enabled. Please turn JavaScript back on and reload this how to find which line error was raised in oracle page. Please enter a title. You can not post a blank
Dbms_utility.format_error_backtrace Example In Oracle
message. Please type your message and try again. More discussions in PL/SQL and SQL All PlacesDatabaseDatabase Application DevelopmentPL/SQL
Oracle Error Stack Trace
and SQL This discussion is archived 3 Replies Latest reply on Feb 27, 2010 2:30 PM by Solomon Yakobson Get line number error muttleychess Feb 27, 2010 2:08
Pl/sql Line Number
PM Hi Is there some way to get line number error when there is some exception ? I use oracle 9.2.02 thank you in advance I have the same question Show 0 Likes(0) 15161Views Tags: none (add) This content has been marked as final. Show 3 replies 1. Re: Get line number error sybrand_b Feb 27, 2010 2:12 what are the methods there in save exceptions in oracle PM (in response to muttleychess) When you don't trap the exception you will get a line number, of the line in error. When you trap the exception you need to use dbms_utility.format_error_stack. Thid will not provide correct line numbers. This issue has been resolved in 10g or 11g, and 9iR2 is going completely out of support in July. ----------- Sybrand Bakker Senikor Oracle DBA Like Show 0 Likes(0) Actions 2. Re: Get line number error Solomon Yakobson Feb 27, 2010 2:17 PM (in response to muttleychess) Not in 9.2, AFAIK. DBMS_UTILITY.FORMAT_ERROR_BACKTRACE was introduced in 10g. SY. Like Show 0 Likes(0) Actions 3. Re: Get line number error Solomon Yakobson Feb 27, 2010 2:30 PM (in response to sybrand_b) sybrand_b wrote: When you trap the exception you need to use dbms_utility.format_error_stack. Thid will not provide correct line numbers. This issue has been resolved in 10g or 11g, and 9iR2 is going completely out of support in July.FORMAT_ERROR_STACK will not provide any line numbers: SQL> select * from v$version 2 / BANNER -----------------
is very important to find the line number on which the error had occurred. The question is how to find that line number. Before Oracle Database 10g $$plsql_line Release 1, the only way to know the line number is to let the pl sql call stack exception go unhandled in your PL/SQL code. In Oracle Database 10g Release 1 and above, you can take advantage of the dbms_utility.format_call_stack example new function DBMS_UTILITY.FORMAT_ERROR_BACKTRACE. This new function returns a formatted string that displays a stack of programs and line numbers leading back to the line on which the error was originally raised. For example, prior https://community.oracle.com/thread/1037981 to 10gR1: SQL> CREATE OR REPLACE PROCEDURE p1 2 IS 3 BEGIN 4 DBMS_OUTPUT.put_line ('in p1, raising error'); 5 RAISE VALUE_ERROR; 6 END; 7 / Procedure created. SQL> CREATE OR REPLACE PROCEDURE p2 2 IS 3 BEGIN 4 DBMS_OUTPUT.put_line ('in p2'); 5 DBMS_OUTPUT.put_line ('calling p1'); 6 p1; 7 END; 8 / Procedure created. SQL> CREATE OR REPLACE PROCEDURE p3 2 IS 3 BEGIN 4 DBMS_OUTPUT.put_line ('in p3, calling p2'); http://awads.net/wp/2006/07/25/how-to-find-where-an-error-was-raised-in-plsql/ 5 p2; 6 END; 7 / Procedure created. Notice the unhandled VALUE_ERROR exception raised in p1. Now, Let's call p3: SQL> BEGIN 2 DBMS_OUTPUT.put_line ('calling p3'); 3 p3; 4 END; 5 / BEGIN * ERROR at line 1: ORA-06502: PL/SQL: numeric or value error ORA-06512: at "HR.P1", line 5 ORA-06512: at "HR.P2", line 6 ORA-06512: at "HR.P3", line 5 ORA-06512: at line 3 As expected, by not handling the exception, the procedure returns an error and we are able to know where the exception was raised. In this example, the error ORA-06502: PL/SQL: numeric or value error was raised at "HR.P1", line 5. Starting with 10gR1, you can call the DBMS_UTILITY.FORMAT_ERROR_BACKTRACE function in your exception handler. Let's use this function in the exception section of procedure p3: SQL> CREATE OR REPLACE PROCEDURE p3 2 IS 3 BEGIN 4 DBMS_OUTPUT.put_line ('in p3, calling p2'); 5 p2; 6 EXCEPTION 7 WHEN OTHERS 8 THEN 9 DBMS_OUTPUT.put_line ('Error stack from p3:'); 10 DBMS_OUTPUT.put_line 11 (DBMS_UTILITY.format_error_backtrace); 12 END; 13 / Procedure created. Let's call p3: SQL> set serveroutput on SQL> BEGIN 2 DBMS_OUTPUT.put_line ('calling p3'); 3 p3; 4 END; 5 / calling p3 in p3, calling p2 in p2 calling p1 in p1, raising error Error stack from p3: ORA
is a PLS_INTEGER literal value indicating the line number reference to $$PLSQL_LINE in the current program unit. In other words, http://awads.net/wp/2006/08/03/heres-a-quick-way-to-get-the-line-number-in-plsql/ $$PLSQL_LINE is the number of the line where $$PLSQL_LINE appears in your PL/SQL code. Another useful predefined inquiry directive is PLSQL_UNIT which is a VARCHAR2 literal value indicating the current source program unit. For a named compilation unit, $$PLSQL_UNIT contains the unit name. For an anonymous block, $$PLSQL_UNIT is NULL. Now, on to some examples: From an anonymous block: EDDIE@XE> BEGIN 2 in oracle DBMS_OUTPUT.put_line ('Line number: ' 3 || $$plsql_line); 4 DBMS_OUTPUT.put_line ('Unit: ' 5 || COALESCE ($$plsql_unit, 'anonymous block') 6 ); 7 END; 8 / Line number: 3 Unit: anonymous block From a procedure: EDDIE@XE> CREATE OR REPLACE PROCEDURE my_proc 2 IS 3 BEGIN 4 DBMS_OUTPUT.put_line ('Line number: ' 5 || $$plsql_line); 6 DBMS_OUTPUT.put_line ('Unit: ' 7 || $$plsql_unit 8 ); 9 END; 10 oracle pl sql / Procedure created. EDDIE@XE> exec my_proc; Line number: 5 Unit: MY_PROC From a package: EDDIE@XE> CREATE OR REPLACE PACKAGE my_pkg 2 IS 3 PROCEDURE my_proc; 4 END; 5 / Package created. EDDIE@XE> CREATE OR REPLACE PACKAGE BODY my_pkg 2 IS 3 PROCEDURE my_proc 4 IS 5 BEGIN 6 DBMS_OUTPUT.put_line ('Line number: ' || $$plsql_line); 7 DBMS_OUTPUT.put_line ( 'Unit: ' 8 || $$plsql_unit 9 ); 10 END; 11 END; 12 / Package body created. EDDIE@XE> exec my_pkg.my_proc; Line number: 6 Unit: MY_PKG Note that $$PLSQL_UNIT returned the package name, not the procedure name. A few days ago, I blogged about how to find where an error was raised in PL/SQL using DBMS_UTILITY.FORMAT_ERROR_BACKTRACE which returns a formatted string that displays a stack of programs and line numbers. But, you must parse the returned string to find the line number and program unit name if you want to use them elsewhere in your programs (like storing them in a log table or using them to query the user_source data dictionary table for example). $$PLSQL_LINE and $$PLSQL_UNIT provide this information without string parsing and manipulation. For example: Using DBMS_UTILITY.FORMAT_ERROR_BAC