Quantcast
Channel: Doyensys Allappsdba Blog..
Viewing all articles
Browse latest Browse all 1640

Script to get SQL ID which has more than one plan hash value.

$
0
0
-- Script to get SQL ID which has more than one plan hash value.
-- This is for last 7 days data from sysdate,


SET SERVEROUTPUT ON
DECLARE
    v_count number := 0;
    CURSOR SQLID IS
    SELECT SQL_ID, COUNT(DISTINCT PLAN_HASH_VALUE) cnt
      FROM DBA_HIST_SQLSTAT STAT, DBA_HIST_SNAPSHOT SS
     WHERE STAT.SNAP_ID = SS.SNAP_ID AND
           SS.DBID = STAT.DBID AND
           SS.INSTANCE_NUMBER = STAT.INSTANCE_NUMBER AND
           SS.BEGIN_INTERVAL_TIME > = SYSDATE-7 AND
           ss.END_INTERVAL_TIME<=sysdate AND
           STAT.PLAN_HASH_VALUE <> 0 AND
           STAT.executions_delta > 0 AND
           STAT.PARSING_SCHEMA_NAME NOT IN ('SYS','SYSTEM')
    GROUP BY SQL_ID
    ORDER BY 1;

BEGIN
    FOR I IN SQLID
    loop
        IF I.cnt > 1 THEN
            DBMS_OUTPUT.PUT_LINE ('We see multiple plan for this sql :-'||I.sql_id||'. Here Considered last 7 days. Please login to DB and check any difference in ETIME by running change.sql.');
        --ELSE
            /** DBMS_OUTPUT.PUT_LINE ('This sqlid '||I.sql_id||' has more than one plan, but the plan was not changed since last 7days.');**/
        END IF;
    end loop;
END;


Viewing all articles
Browse latest Browse all 1640

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>