根据操作系统的PID查SESSION的SID
select sid
from v$session
where paddr=(select addr from v$process where spid='1098994');
根据SESSION的SID查操作系统的PID
select spid
from v$process
where addr=(select paddr from v$session where sid='152');
察看当前Session的sid
select distinct sid from v$mystat;
SID
----------
143
column pid new_value Pid
column sid new_value Sid
column serial# new_value Serial
select
p.pid,
p.spid,
s.sid,
s.serial#
from
sys.v_$session s,
sys.v_$process p
where
s.sid = (select sid from sys.v_$mystat where rownum = 1) and
p.addr = s.paddr
/
PID SID SERIAL#
---------- ---------- ----------
24 143 188
-------UNIX系统捕获SQL
SQL> select distinct sid from v$mystat;
SID
----------
159
SQL> select spid from v$process
where addr=(select paddr from v$session where sid='159');
SPID
------------
4275
SQL> select /*+ ORDERED */ sql_text from v$sqltext a
where a.hash_value = (
select sql_hash_value from v$session b
where b.paddr = (
select addr from v$process c
where c.spid = '&spid'
)
)
order by piece asc
/
Enter value for spid: 4275
old 6: where c.spid = '&spid'
new 6: where c.spid = '4275'
SQL_TEXT
----------------------------------------------------------------
select /*+ ORDERED */ sql_text from v$sqltext a where a.hash_val
ue = ( select sql_hash_value from v$session b where b.paddr = (
select addr from v$process c where c.spid = '4275' ) ) order by
piece asc