Let's Join and share our day to day activities, Views, Knowledge, Questions and achievements in Oracle Database (8i / 9i / 10g or 11g)

Sep 22, 2010

How to find last SQL running on Database


SQL> spool D:\lastsql.lst
Enter value for filename:
SQL> set verify off lines 132 head on
SQL>
SQL>
SQL> col UNAM format a20  word  heading 'User'
SQL> col STMT format a56  word  heading 'Statement'
SQL> col RUNT format a08  word  heading 'Run Time'
SQL> col ltim format a20 word heading 'Logon Time'
SQL> col etim format a20 word heading 'Connect Time'
SQL> col PROG format a30 word heading 'Program|Client Terminal Details'
SQL> col SID  format a10 word heading 'SID/|Serial#'
SQL> col DR   format 999999999 heading 'Disk Reads'
SQL> col BG   format 999999999 heading 'Buffer Gets'
SQL> col thread   format 99999 heading 'ThreadID
string "'ThreadID" missing terminating quote (').
SQL> col sqltext format A64 wrap heading 'Last SQL'
SQL>
SQL> break on unam on sid on status
SQL>
SQL> select S.USERNAME||'('||s.sid||')-'||s.osuser     UNAM
  2  --      ,s.program||'-'||s.terminal||'('||s.machine||')' PROG
  3        ,s.sid||'/'||s.serial# sid
  4       ,s.status "Status",p.spid
  5       ,sql_text sqltext
  6  from v$sqltext_with_newlines t,V$SESSION s , v$process p
  7  where t.address =s.sql_address
  8  and p.addr=s.paddr(+)
  9  and t.hash_value = s.sql_hash_value
 10  order by s.sid,t.piece
 11  /


* Please test this script before use. Author will not be responsible for any damage that may be cause by this script.

No comments:

Post a Comment