Skip to Main Content
  • Questions
  • How to observe current values of a running plsql code.

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Alex.

Asked: October 07, 2016 - 5:10 pm UTC

Last updated: October 08, 2016 - 2:07 am UTC

Version: 12.1.0.2

Viewed 1000+ times

You Asked

Hello,
I can observe the current value of a bind variable, using v$sql_bind_capture. I don't know how to do it, when having no bind variable.
Having a simple code like this below, I would like to see a VALUE of rec.column1 being passed to my_function.

begin
  for rec in (select column1 from tab_A) loop
    my_function(rec.column1);
  end loop;
end;


How to achieve that starting from v$session? There are no obvious bindings here.
When running long executing scripts, I would like to spy and verify where I am with the execution.

and Connor said...

An application is only as good as its instrumentation. A great blog post on that here

http://asktom.oracle.com/Misc/instrumentation.html

So a common technique would be something like:

begin
  for rec in (select column1 from tab_A) loop
    dbms_application_info.set_client_info('Currently on '||i.column1);
    my_function(rec.column1);
  end loop;
end;


and that can be viewed on v$session from any *other* session

Another option (if you want to *halt* the code) is to use the SQLDeveloper debugger

http://www.thatjeffsmith.com/archive/2014/02/how-to-start-the-plsql-debugger/

http://www.thatjeffsmith.com/archive/2015/06/everything-you-ever-wanted-to-know-about-the-plsql-debugger/

Is this answer out of date? If it is, please let us know via a Comment

More to Explore

DBMS_APPLICATION_INFO

More on PL/SQL routine DBMS_APPLICATION_INFO here