@@header

/*
*
*  Author    : Vishal Gupta
*  Purpose   : Display hourly load profile from AWR for statistics passed as input
*              All figures delta between two consecutive snapshots
*  Parameter : 1 - InstanceNumber (Use % for all instances)
*              2 - From Timestamp (In YYYY-MM-DD HH24:MI:SS format)
*              3 - To Timestamp   (In YYYY-MM-DD HH24:MI:SS format)
*              4 - Statistics Name (Exact Name, use @statname script to find exact name)           
*            
*
*
*  Revision History:
*  ===================
*  Date       Author        Description
*  ---------  ------------  -----------------------------------------
*  25-May-12  Vishal Gupta  Intial version
*  
*/


/************************************
*  INPUT PARAMETERS
************************************/
UNDEFINE INST_ID
UNDEFINE FROM_TIMESTAMP
UNDEFINE FROM_TIMESTAMP
UNDEFINE STAT_NAME

DEFINE INST_ID="&&1"
DEFINE FROM_TIMESTAMP="&2"
DEFINE TO_TIMESTAMP="&3"
DEFINE STAT_NAME="&4"

/************************************
*  CONFIGURATION PARAMETERS
************************************/



DEFINE FORMAT="9999"
DEFINE TOTAL_FORMAT="999,999"

--DEFINE HEADING="#"
--DEFINE DIVIDER="1"
--DEFINE HEADING="'1000s"
--DEFINE DIVIDER="1000"

--DEFINE HEADING="min"
--DEFINE DIVIDER="60/100"
--DEFINE HEADING="hr"
--DEFINE DIVIDER="60/60/100"

--DEFINE HEADING="KB"
--DEFINE DIVIDER="1024"
--DEFINE HEADING="MB"
--DEFINE DIVIDER="1024/1024"
DEFINE HEADING="GB"
DEFINE DIVIDER="1024/1024/1024"




PROMPT 
PROMPT ####################################################################################
PROMPT #
PROMPT #   S Y S T E M    S T A T I S T I C S   T R E N D 
PROMPT #  
PROMPT #   From AWR Repository (Absolute figures , not delta)
PROMPT #   - Statistic Name  - "&&STAT_NAME"
PROMPT #   - For Instance ID - &INST_ID
PROMPT #   - Snap Between    - &&FROM_TIMESTAMP and &&TO_TIMESTAMP (YYYY-MM-DD HH24:MI:SS)
PROMPT #
PROMPT #   (All Figures are in &&HEADING)
PROMPT #
PROMPT ####################################################################################


COLUMN "Date"  HEADING "Date"            FORMAT A9
COLUMN "Day"   HEADING "Day"             FORMAT A3
COLUMN Day_Max HEADING "Day|Max"       FORMAT &&TOTAL_FORMAT
COLUMN h0      HEADING "h0"              FORMAT &&FORMAT
COLUMN h1      HEADING "h1"              FORMAT &&FORMAT
COLUMN h2      HEADING "h2"              FORMAT &&FORMAT
COLUMN h3      HEADING "h3"              FORMAT &&FORMAT
COLUMN h4      HEADING "h4"              FORMAT &&FORMAT
COLUMN h5      HEADING "h5"              FORMAT &&FORMAT
COLUMN h6      HEADING "h6"              FORMAT &&FORMAT
COLUMN h7      HEADING "h7"              FORMAT &&FORMAT
COLUMN h8      HEADING "h8"              FORMAT &&FORMAT
COLUMN h9      HEADING "h9"              FORMAT &&FORMAT
COLUMN h10     HEADING "h10"             FORMAT &&FORMAT
COLUMN h11     HEADING "h11"             FORMAT &&FORMAT
COLUMN h12     HEADING "h12"             FORMAT &&FORMAT
COLUMN h13     HEADING "h13"             FORMAT &&FORMAT
COLUMN h14     HEADING "h14"             FORMAT &&FORMAT
COLUMN h15     HEADING "h15"             FORMAT &&FORMAT 
COLUMN h16     HEADING "h16"             FORMAT &&FORMAT
COLUMN h17     HEADING "h17"             FORMAT &&FORMAT
COLUMN h18     HEADING "h18"             FORMAT &&FORMAT
COLUMN h19     HEADING "h19"             FORMAT &&FORMAT
COLUMN h20     HEADING "h20"             FORMAT &&FORMAT
COLUMN h21     HEADING "h21"             FORMAT &&FORMAT
COLUMN h22     HEADING "h22"             FORMAT &&FORMAT
COLUMN h23     HEADING "h23"             FORMAT &&FORMAT

SELECT /*+ USE_NL(s ss) */ 
      TO_CHAR(trunc(s.end_interval_time),'DD-Mon-YY') "Date"
    , TO_CHAR(trunc(s.end_interval_time), 'Dy') "Day"
    , ROUND(MAX(ss.value) / &&DIVIDER ) Day_Max
    , ROUND(MAX(DECODE(TO_CHAR(s.end_interval_time, 'hh24'),'00',(ss.value),0)) / &&DIVIDER ) "h0"
    , ROUND(MAX(DECODE(TO_CHAR(s.end_interval_time, 'hh24'),'01',(ss.value),0)) / &&DIVIDER ) "h1"
    , ROUND(MAX(DECODE(TO_CHAR(s.end_interval_time, 'hh24'),'02',(ss.value),0)) / &&DIVIDER ) "h2"
    , ROUND(MAX(DECODE(TO_CHAR(s.end_interval_time, 'hh24'),'03',(ss.value),0)) / &&DIVIDER ) "h3"
    , ROUND(MAX(DECODE(TO_CHAR(s.end_interval_time, 'hh24'),'04',(ss.value),0)) / &&DIVIDER ) "h4"
    , ROUND(MAX(DECODE(TO_CHAR(s.end_interval_time, 'hh24'),'05',(ss.value),0)) / &&DIVIDER ) "h5"
    , ROUND(MAX(DECODE(TO_CHAR(s.end_interval_time, 'hh24'),'06',(ss.value),0)) / &&DIVIDER ) "h6"
    , ROUND(MAX(DECODE(TO_CHAR(s.end_interval_time, 'hh24'),'07',(ss.value),0)) / &&DIVIDER ) "h7"
    , ROUND(MAX(DECODE(TO_CHAR(s.end_interval_time, 'hh24'),'08',(ss.value),0)) / &&DIVIDER ) "h8"
    , ROUND(MAX(DECODE(TO_CHAR(s.end_interval_time, 'hh24'),'09',(ss.value),0)) / &&DIVIDER ) "h9"
    , ROUND(MAX(DECODE(TO_CHAR(s.end_interval_time, 'hh24'),'10',(ss.value),0)) / &&DIVIDER ) "h10"
    , ROUND(MAX(DECODE(TO_CHAR(s.end_interval_time, 'hh24'),'11',(ss.value),0)) / &&DIVIDER ) "h11"
    , ROUND(MAX(DECODE(TO_CHAR(s.end_interval_time, 'hh24'),'12',(ss.value),0)) / &&DIVIDER ) "h12"
    , ROUND(MAX(DECODE(TO_CHAR(s.end_interval_time, 'hh24'),'13',(ss.value),0)) / &&DIVIDER ) "h13"
    , ROUND(MAX(DECODE(TO_CHAR(s.end_interval_time, 'hh24'),'14',(ss.value),0)) / &&DIVIDER ) "h14"
    , ROUND(MAX(DECODE(TO_CHAR(s.end_interval_time, 'hh24'),'15',(ss.value),0)) / &&DIVIDER ) "h15"
    , ROUND(MAX(DECODE(TO_CHAR(s.end_interval_time, 'hh24'),'16',(ss.value),0)) / &&DIVIDER ) "h16"
    , ROUND(MAX(DECODE(TO_CHAR(s.end_interval_time, 'hh24'),'17',(ss.value),0)) / &&DIVIDER ) "h17"
    , ROUND(MAX(DECODE(TO_CHAR(s.end_interval_time, 'hh24'),'18',(ss.value),0)) / &&DIVIDER ) "h18"
    , ROUND(MAX(DECODE(TO_CHAR(s.end_interval_time, 'hh24'),'19',(ss.value),0)) / &&DIVIDER ) "h19"
    , ROUND(MAX(DECODE(TO_CHAR(s.end_interval_time, 'hh24'),'20',(ss.value),0)) / &&DIVIDER ) "h20"
    , ROUND(MAX(DECODE(TO_CHAR(s.end_interval_time, 'hh24'),'21',(ss.value),0)) / &&DIVIDER ) "h21"
    , ROUND(MAX(DECODE(TO_CHAR(s.end_interval_time, 'hh24'),'22',(ss.value),0)) / &&DIVIDER ) "h22"
    , ROUND(MAX(DECODE(TO_CHAR(s.end_interval_time, 'hh24'),'23',(ss.value),0)) / &&DIVIDER ) "h23"
FROM dba_hist_snapshot s
   , dba_hist_sysstat ss
where s.dbid = ss.dbid
  and s.instance_number = ss.instance_number
  and s.snap_id = ss.snap_id
  and ss.stat_name = '&&STAT_NAME'
  AND s.instance_number LIKE '&&INST_ID'
  AND s.end_interval_time BETWEEN TO_TIMESTAMP('&&FROM_TIMESTAMP','YYYY-MM-DD HH24:MI:SS') 
                              AND TO_TIMESTAMP('&&TO_TIMESTAMP'  ,'YYYY-MM-DD HH24:MI:SS')
GROUP BY trunc(s.end_interval_time) 
--       , to_char(COMPLETION_TIME, 'Dy')
ORDER BY trunc(s.end_interval_time) asc
/


@@footer
