Strauteka
Strauteka

Reputation: 198

Oracle pl/sql code line(row) to variable

So is it possible to get current code line?

1,2,3,4 v_variable :=(get_line or something???) and in variable are value 4?
5,6,7,8,9 v_variable :=(get_line or something???) and in variable are value 9?

I just want to find easiest way to catch bugs Thanks.

1,2,3,4, code lines...

Upvotes: 3

Views: 3078

Answers (3)

Adarsh
Adarsh

Reputation: 3641

The oracle exception handling system helps you do exactly what you need. Instead of manually getting line numbers, you can raise and handle user defined exceptions or system exceptions and in the exception blocks use the following code to fetch the lin number where the error occurred.

DBMS_UTILITY.FORMAT_ERROR_BACKTRACE

Read this article for more information and examples.

http://www.oracle.com/technetwork/issue-archive/2005/05-mar/o25plsql-093886.html

Upvotes: 2

user272735
user272735

Reputation: 10648

I just want to find easiest way to catch bugs

The easiest way to find bugs is called unit testing. Apply rigorously with test driven development and after a while you won't have many bugs at all !

Internet is not short of instructions nor Stack Overflow short of questions about both subjects. Start e.g. with:

Upvotes: 0

Nick Krasnov
Nick Krasnov

Reputation: 27251

So is it possible to get current code line?

Yes, it's possible. Starting from Oracle 10g the $$PLSQL_LINE inquiry directive can be used to return number of a line in the code where $$PLSQL_LINE appears:

SQL> declare
  2    l_cur_cl pls_integer;
  3  begin
  4    l_cur_cl := $$PLSQL_LINE;
  5    dbms_output.put_line('Line #: '|| to_char(l_cur_cl) || chr(13)
  6                         || 'Current line #:  '|| to_char($$PLSQL_LINE));
  7  end;
  8  /

Output:

Line #: 4
Current line #:  6
PL/SQL procedure successfully completed

Upvotes: 10

Related Questions