Skip to Main Content
  • Questions
  • Extracting execution plan for PL/SQL block

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Tanuja.

Asked: March 26, 2018 - 8:20 pm UTC

Last updated: February 25, 2021 - 5:32 am UTC

Version: 11.2.0.4.0

Viewed 1000+ times

You Asked

Hi Tom, 

Need help extracting execution plan  for  any anonymous PL/SQL block . 

I am able to extract execution plan for SQL using explain plan but it doesn't work for pl/sql block 


EXPLAIN PLAN FOR 
select * from dual; 

select * from plan_table 



--we are trying extract execution plan for all quries inside a block 





DECLARE 

 l_date DATE; 

BEGIN 

 select sysdate 

 INTO l_Date 

 FROM DUAL; 

 DBMS_OUTPUT.put_line (l_date); 



 --this block will have multiple queries 


END; 

/ 


Can you please help ? 

Thanks , 
Tanu 


and Connor said...

There is a SQL_ID for a PLSQL block, but not an "execution plan" as such. Only the SQL queries that are run from within that block will have an execution plan.

If you want to tie a SQL to a PLSQL unit, see my blog post for how this is done.

https://connor-mcdonald.com/2016/01/20/problematic-sql-plsql-is-your-friend/

Rating

  (1 rating)

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

Comments

not executed inside plsql code

sunny, February 24, 2021 - 9:19 am UTC

following is a script when i run this script not executed output of " 1 ".
my variable is also assign with 'N' value and '121212' is not null string so what is wrong why if condition becomes false

declare

v_str char(2);

begin

v_str := 'N';


if '121212' is not null and nvl(v_str, 'N') = 'N' then
dbms_output.put_line('1 ' || v_str);
end if;
dbms_output.put_line('2 ' || v_str);
end;



Connor McDonald
February 25, 2021 - 5:32 am UTC

CHAR(2) means your string is:

N-space

not just

N

More to Explore

Performance

Get all the information about database performance in the Database Performance guide.