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...

Answers


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

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


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:


Need Your Help

Smart pointer question

c++ pointers boost smart-pointers

I'm rewriting my code with smart pointer. I have such situation:

Using a script how do I create a text file that contains all of the filenames in a directory C:\sample\?

windows batch-file

Using a script how do I create a text file that contains all of the filenames in a directory C:\sample\?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.