SELECT LTRIM(SUBSTR(NVL(s.username, '(oracle)') ,1 ,11)) as USERNAME,
LTRIM(SUBSTR(s.osuser ,1 ,8)) as OSUSER,
LTRIM(SUBSTR(TO_CHAR(s.sid) ,1 ,4)) as SID,
LTRIM(SUBSTR(TO_CHAR(s.serial#) ,1 ,7)) as SERIAL#,
LTRIM(SUBSTR(TO_CHAR(p.spid) ,1 ,5)) as SPID,
LTRIM(SUBSTR(s.lockwait ,1 ,8)) as LOCKWAIT,
LTRIM(SUBSTR(s.status ,1 ,8)) as STATUS,
--s.module,
--s.machine,
LTRIM(SUBSTR(s.program ,1 ,20)) as PROGRAM,
LTRIM(SUBSTR(TO_CHAR(s.logon_Time,'DD-MON-YYYY HH24:MI:SS') ,1 ,20)) as LOGON_TIME,
LTRIM(SUBSTR(a.sql_text ,1 ,70)) as SQL
FROM v$session s, v$process p, v$sqlarea a
WHERE s.paddr = p.addr
and s.sql_id=a.sql_id
and (s.status = 'ACTIVE' or s.status = 'KILLED')
ORDER BY s.username, s.osuser;
SELECT LTRIM(SUBSTR(NVL(s.username, '(oracle)') ,1 ,11)) as USERNAME,
LTRIM(SUBSTR(s.osuser ,1 ,8)) as OSUSER,
LTRIM(SUBSTR(TO_CHAR(s.sid) ,1 ,4)) as SID,
LTRIM(SUBSTR(TO_CHAR(s.serial#) ,1 ,7)) as SERIAL#,
LTRIM(SUBSTR(TO_CHAR(p.spid) ,1 ,5)) as SPID,
LTRIM(SUBSTR(s.lockwait ,1 ,8)) as LOCKWAIT,
LTRIM(SUBSTR(s.status ,1 ,8)) as STATUS,
--s.module,
--s.machine,
LTRIM(SUBSTR(s.program ,1 ,20)) as PROGRAM,
LTRIM(SUBSTR(TO_CHAR(s.logon_Time,'DD-MON-YYYY HH24:MI:SS') ,1 ,20)) as LOGON_TIME,
Decode(b.locked_mode, 0, 'None',
1, 'Null (NULL)',
2, 'Row-S (SS)',
3, 'Row-X (SX)',
4, 'Share (S)',
5, 'S/Row-X (SSX)',
6, 'Exclusive (X)',
b.locked_mode) as LOCKED_MODE,
LTRIM(SUBSTR(a.object_name ,1 ,57)) as OBJECT_NAME
FROM v$session s, v$process p, dba_objects a, v$locked_object b
WHERE s.paddr = p.addr
and b.session_id=s.sid
and a.object_id = b.object_id
and (s.status = 'ACTIVE' or s.status = 'KILLED')
ORDER BY s.username, s.osuser;