Skip to Main Content

Breadcrumb

Question and Answer

Chris Saxon

Thanks for the question, Pradeep.

Asked: January 25, 2018 - 4:27 pm UTC

Last updated: January 26, 2018 - 4:22 pm UTC

Version: 11.2.0.4

Viewed 10K+ times! This question is

You Asked

Dear Team,

How to find the sql_id associated with execution of a particular pl/sql procedure on a given day in past to see problem.

means how can i find pl/sql sql_id and its last execution date and time.


Thanks
Pradeep

and Chris said...

The same way you'd find a SQL statement: look for it in the v$ views!

create or replace procedure p1 ( p int ) as
begin
  null;
end p1;
/

begin 
  p1(1);
end;
/

call p1(1);

exec p1(1);

select sql_id, sql_text from v$sql
where  upper(sql_text) like '%P1(1)%'
and    sql_text not like '%not this%';

SQL_ID          SQL_TEXT              
curcusf2wkc2p   begin   p1(1); end;   
93rz7mjcffpf3   BEGIN p1(1); END;     
1csakzn21fu7g   call p1(1)  


Of course, this only applies if it's a top-level call. If you're looking for a procedure called within another, you're out of luck:

create or replace procedure p2 ( p int ) as
begin
  null;
end p2;
/

create or replace procedure p1 ( p int ) as
begin
  p2(p);
end p1;
/

exec p1(1);

select sql_id, sql_text from v$sql
where  upper(sql_text) like '%P2(%)%';

SQL_ID          SQL_TEXT                                                                   
34wxm6wdmr5nh   select sql_id, sql_text from v$sql where  upper(sql_text) like '%P2(%)%'


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

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