Script to Show Plan Baseline
set long 32767
set pages 9999
set lines 140
set verify off
accept sql_id prompt "Enter the SQL ID : ";
variable sql_id varchar2
COLUMN sql_id FORMAT A13
COLUMN sql_handle FORMAT A21 newline
COLUMN plan_name FORMAT A31
COLUMN origin FORMAT A14
COLUMN enabled FORMAT A7
COLUMN accepted FORMAT A8
COLUMN fixed FORMAT A5
COLUMN autopurge FORMAT A9
COLUMN CREATED FORMAT A19
COLUMN sql_text FORMAT A130 word_wrapped newline heading sql_text
column signature format 99999999999999999999
column sql_id format a13
select -- sql_text sql_text,
s.sql_id, signature, EXECUTIONS,
round(ELAPSED_TIME/decode(EXECUTIONS, 0, 1, EXECUTIONS),2) ELAPSED_TIME,
round(CPU_TIME/decode(EXECUTIONS, 0, 1, EXECUTIONS),2) CPU_TIME,
round(BUFFER_GETS/decode(EXECUTIONS, 0, 1, EXECUTIONS),2) BUFFER_GETS,
round(DISK_READS/decode(EXECUTIONS, 0, 1, EXECUTIONS),2) DISK_READS, OPTIMIZER_COST,
sql_handle, plan_name, origin, enabled, accepted, fixed, autopurge,
to_char(CREATED , 'mm/dd/yyyy hh24:mi:ss') CREATED
from dba_sql_plan_baselines spb,
(select distinct exact_matching_signature, sql_id
from v$sql) s
where s.exact_matching_signature (+) = spb.SIGNATURE
and (s.sql_id like '%&SQL_ID%')
order by CREATED
/