@@header

DEFINE SID="&1"
DEFINE INST_ID="&2"

COLUMN spid FORMAT a6
COLUMN SID FORMAT 99999
COLUMN SERIAL# FORMAT 99999
COLUMN username FORMAT a12
COLUMN osuser FORMAT a12   TRUNCATE
COLUMN machine FORMAT a20  TRUNCATE
COLUMN program FORMAT a20  TRUNCATE
COLUMN sql_text FORMAT a80 TRUNCATE


Prompt 
Prompt #######  SQLs Executed ######################
Prompt 

select s.SID
     , s.inst_id
     , sql.sql_id
     , sql.sql_text
from  gv$session s, gv$process p, gv$open_cursor c, gv$sqltext sql
where s.PADDR = p.ADDR
AND   s.inst_id = p.inst_id
and   s.sid     = c.sid
AND   s.inst_id = c.inst_id
AND   c.inst_id = sql.inst_id
and   c.address = sql.address
and   c.hash_value = sql.hash_value
AND   s.sid = '&SID'
AND   s.inst_id = '&INST_ID'
AND   sql.piece = 0
;

Prompt 
Prompt #######  SQLs Executed (From ASH)######################
Prompt 

select s.SID
     , s.inst_id
     , sql.sql_id
     , sql.sql_text
from  gv$session s, gv$active_session_history ash, gv$sqltext sql
where ash.inst_id = s.inst_id
and   ash.session_id = s.sid
and   ash.session_serial# = s.serial#
AND   sql.inst_id = ash.inst_id
AND   sql.sql_id  = ash.sql_id
AND   s.sid = '&SID'
AND   s.inst_id = '&INST_ID'
AND   sql.piece = 0
;


@@footer
