@header

/*
*
*  Author        : Vishal Gupta
*  Purpose       : Display Session Details
*  Compatibility : 10.1 and above
*  Parameters    : 1 - SID
*                  2 - INST_ID (optional, default to 1)
*
*  Revision History:
*  ===================
*  Date       Author        Description
*  ---------  ------------  --------------------------------------------------
*  27-Aug-04  Vishal Gupta  Created
*
*/


/************************************
*  INPUT PARAMETERS
************************************/

VARIABLE SID number ;
VARIABLE INST_ID number ;

 BEGIN
    :SID := '&&1';
    :INST_ID := NVL('&&2',1);
    IF :INST_ID = '' OR :INST_ID IS NULL THEN
       :INST_ID := 1;
    END IF;   
END;
/


PROMPT
PROMPT ######### Session Wait History #####################

COLUMN inst_id               HEADING "I#"                       FORMAT 99
COLUMN SID                   HEADING "SID"                      FORMAT 99999
COLUMN seq#                                                     FORMAT 999
COLUMN state                                                    FORMAT a10
COLUMN event                 HEADING "EventName"                FORMAT a40
COLUMN wait_time             HEADING "Wait|(ms)"                FORMAT 99,999        
COLUMN TIME_SINCE_LAST_WAIT  HEADING "TimeSince|LastWait|(ms)"  FORMAT 999,999        
COLUMN p1                                                       FORMAT 9999999999
COLUMN p2                                                       FORMAT 9999999999
COLUMN p3                                                       FORMAT 9999999999
COLUMN p1text                                                   FORMAT a20 
COLUMN p2text                                                   FORMAT a20 
COLUMN p3text                                                   FORMAT a20 

SELECT w.sid
     , w.inst_id
     , w.seq#
     , w.event
     , w.wait_time * 10 wait_time
     , w.TIME_SINCE_LAST_WAIT_MICRO/1000 TIME_SINCE_LAST_WAIT
     , w.p1
     , w.p1text
     , w.p2
     , w.p2text
     , w.p3
     , w.p3text
FROM   gv$session_wait_history w
WHERE  w.sid  = :SID
AND    w.inst_id = :INST_ID
ORDER BY seq#
/


@@footer
