1. VARIABLE rpt_options NUMBER;  

  2. DEFINE no_options = 0;  

  3. define ENABLE_ADDM = 8;    

  4. REM according to your needs, the value can be 'text' or 'html'    

  5. DEFINE report_type='html';    

  6. BEGIN  

  7.   :rpt_options := &no_options;  

  8. END;  

  9. /    

  10. VARIABLE dbid NUMBER;  

  11. VARIABLE inst_num NUMBER;  

  12. VARIABLE bid NUMBER;  

  13. VARIABLE eid NUMBER;  

  14. BEGIN  

  15.  SELECT MIN (snap_id) INTO :bid  

  16.    FROM dba_hist_snapshot  

  17.   WHERE TO_CHAR (end_interval_time, 'yyyymmdd') = TO_CHAR (SYSDATE-1, 'yyyymmdd');  

  18.   SELECT MAX (snap_id) INTO :eid FROM dba_hist_snapshot WHERE TO_CHAR (begin_interval_time,'yyyymmdd') = TO_CHAR (SYSDATE-1, 'yyyymmdd');  

  19.  SELECT dbid INTO :dbid FROM v$database;    

  20. SELECT instance_number INTO :inst_num FROM v$instance;  

  21. END;  

  22. /    

  23. COLUMN ext NEW_VALUE ext NOPRINT  

  24. COLUMN fn_name NEW_VALUE fn_name NOPRINT;  

  25. COLUMN lnsz NEW_VALUE lnsz NOPRINT;  

  26. SELECT 'txt' ext  

  27.  FROM DUAL  

  28. WHERE LOWER ('&report_type') = 'text';    

  29. SELECT 'html' ext  

  30.  FROM DUAL  

  31. WHERE LOWER ('&report_type') = 'html';  

  32. SELECT 'awr_report_text' fn_name  

  33.  FROM DUAL  

  34. WHERE LOWER ('&report_type') = 'text';    

  35. SELECT 'awr_report_html' fn_name  

  36.  FROM DUAL  

  37. WHERE LOWER ('&report_type') = 'html';    

  38. SELECT '80' lnsz  

  39.  FROM DUAL  

  40. WHERE LOWER ('&report_type') = 'text';    

  41. SELECT '1500' lnsz  

  42.  FROM DUAL  

  43. WHERE LOWER ('&report_type') = 'html';    

  44. set linesize &lnsz;  

  45. COLUMN report_name NEW_VALUE report_name NOPRINT;  

  46. SELECT instance_name || '_awrrpt_' || instance_number || '_' || b.timestamp || '.' || '&ext'  report_name  FROM v$instance a,(SELECT TO_CHAR(begin_interval_time,'yyyymmdd') timestamp  FROM dba_hist_snapshot  WHERE snap_id = :eid) b;  

  47. SET TERMOUT OFF;  

  48. SPOOL $AWR_DIR/&report_name;  

  49. SELECT output  

  50.  FROM TABLE (DBMS_WORKLOAD_REPOSITORY.&fn_name (:dbid,  

  51.                                                 :inst_num,  

  52.                                                 :bid,  

  53.                                                 :eid,  

  54.                                                 :rpt_options));  

  55. SPOOL OFF;  

  56. SET TERMOUT ON;  

  57. CLEAR COLUMNS SQL;  

  58. TTITLE OFF;  

  59. BTITLE OFF;  

  60. REPFOOTER OFF;    

  61. UNDEFINE report_name  

  62. UNDEFINE report_type  

  63. UNDEFINE fn_name  

  64. UNDEFINE lnsz  

  65. UNDEFINE no_options