Skip to Main Content
  • Questions
  • showing PL/SQL code and SQL statement relationship

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Philippe.

Asked: November 29, 2018 - 2:11 pm UTC

Last updated: December 03, 2018 - 3:26 am UTC

Version: 12.1.0. 2

Viewed 1000+ times

You Asked

Hi Oracle Gurus,

I’m banging my head into walls for some time trying to set up queries monitoring DB activity that would show relationship between a PL/SQL code ( anonymous block, function or stored procedure) and the statement issued inside.

For instance if I run the anonymous block :

Declare
  NumRecords NUMBER;
begin
  FOR i IN 1..100000 LOOP
  select count(*) into NumRecords from V$session;  
  END LOOP;
end;


Then I query views such as v$SQL, v$SQLAREA, v$active_session_history and I get 2 records, 1 for…
select count(*)from V$session;  

and 1 for…
declare    NumRecords NUMBER;    begin… 


But I cannot show that the statement was run from the PL block. I cannot find a way to show this in Oracle system views. Any tips to do this would be great.

Thanks in advance for your help

Philippe

and Connor said...

Rating

  (1 rating)

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

Comments

Great answer...

Philippe Marchand, November 30, 2018 - 4:11 pm UTC

Hi Connor,

Many many thanks for the quick feedback. This is what I was looking for. So using this you can easily rely this to the parent procedure or function. The only issue remaining is with anonymous PL/SQL block. Actually you can guess that the statement is coming from an anonymous PL/SQL as PROGRAM_LINE# is not 0 but you can’t rely to the block as it doesn’t have V$SQL.PROGRAM_ID and thus DBA_OBJECTS.OBJECT_ID, right?
Anyway this is a very useful information.

Thank’s again and have a great week end.

Philippe

Connor McDonald
December 03, 2018 - 3:26 am UTC

That is my understanding yes.

More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library