/**********************************************************************
* File: sqlhistory.sql
* Type: SQL*Plus script
* Author: Tim Gorman (Evergreen Database Technologies, Inc.)
* Date: 1May2015
*
* Description:
* SQL*Plus script to query the "history" of a specified SQL
* statement, using its "SQL ID" across all database instances
* in a database, using the AWR repository. This report is useful
* for obtaining an hourly perspective on SQL statements seen in
* more aggregated reports.
*
* Modifications:
* TGorman 29sep08 adapted from the earlier STATSPACK-based
* "sphistory.sql" script
* Anbob 2015/5/1 add instance number indentify
* Anbob 07Api23 add more delta
* Call:
* @sqlhistory --request sql_id and days
*********************************************************************/
set echo off
set feedback off timing off verify off pagesize 100 linesize 300 recsep off
set serveroutput on size 1000000 format wrapped trimout on trimspool on
col phv heading "Plan|Hash Value"
col snap_time format a12 truncate heading "Snapshot|Time"
col execs format 999,990 heading "Execs"
col lio_per_exec format 999,999,990.00 heading "Avg LIO|Per Exec"
col rows_per_exec format 999,999,990.00 heading "Avg Rows|Per Exec"
col pio_per_exec format 999,999,990.00 heading "Avg PIO|Per Exec"
col cpu_per_exec format 999,999,990.00 heading "Avg|CPU (secs)|Per Exec"
col ela_per_exec format 999,999,990.00 heading "Avg|Elapsed (secs)|Per Exec"
col IOW_per_exec format 9,999,990.00 heading "Avg|IO(secs)|Per Exec"
col CLW_per_exec format 9,999,990.00 heading "Avg|Clus(secs)|Per Exec"
col AQW_per_exec format 9,999,990.00 heading "Avg|APP (secs)|Per Exec"
col CCW_per_exec format 9,999,990.00 heading "Avg|Conc(secs)|Per Exec"
col off_per_exec format 9,999,990.00 heading "Avg|Celoff(secs)|Per Exec"
col VERSION_COUNT format 999 "Ver|cnt"
col sql_text format a64 heading "Text of SQL statement"
col instance_number for 9999 heading "Inst"
clear breaks computes
ttitle off
btitle off
accept V_SQL_ID prompt "Enter the SQL_ID: "
accept V_NBR_DAYS prompt "Enter number of days (backwards from this hour) to
report (default: ALL): "
variable v_nbr_days number
spool sqlhistory_&&V_SQL_ID
declare
cursor get_phv(in_sql_id in varchar2, in_days in integer)
is
select ss.plan_hash_value,
min(s.begin_interval_time) min_time,
max(s.begin_interval_time) max_time,
min(s.snap_id) min_snap,
max(s.snap_id) max_snap,
评论