@@header


/*
*
*  Author  : Vishal Gupta
*  Purpose : Display system statistics history
*
*  Revision History:
*  ===================
*  Date       Author        Description
*  ---------  ------------  -----------------------------------------
*  29-Dec-14  Vishal Gupta  Created
*
*/


COLUMN savtime          HEADING "SaveTime"         FORMAT a25
COLUMN sname            HEADING "Stat Type"        FORMAT a15
COLUMN pname            HEADING "Stat Name"        FORMAT a15
COLUMN value            HEADING "Value"            FORMAT a30

SELECT NVL(TO_CHAR(savtime,'DD-MON-YYYY HH24:MI:SS'),'Current') savtime
     , pname
     , value
FROM
(
SELECT savtime
     , pname
	    , TRIM(NVL(TO_CHAR(pval1,'999,999,999'),pval2)) value
  FROM sys.wri$_optstat_aux_history
UNION ALL
SELECT NULL
     , pname
     , TRIM(NVL(TO_CHAR(pval1,'999,999,999'),pval2)) value
FROM  sys.aux_stats$
WHERE sname = 'SYSSTATS_MAIN'
) a
ORDER BY a.savtime NULLS LAST, pname
;


@@footer