Retrieve an old SQL Plan

This script will use a sql_id to retrieve the execution plan for the query.

with aa as (
            SELECT DISTINCT ss.sql_id, ss.plan_hash_value
            FROM   DBA_HIST_SQLSTAT SS
            WHERE  SS.SQL_ID = ‘&sql_id’
)
SELECT b.*
  from aa, table(dbms_xplan.display_awr(aa.sql_id,aa.plan_hash_value)) b
/

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>