查看当前会话的session ID 有如下三种方法:
1. v$mystat视图
SQL> select sid from v$mystat where rownum=1;
SID
----------
1152
2. 使用userenv(‘sid’) 直接获取
这种方法只能在oracle 10g以后可以使用。
SQL> select userenv('sid') from dual;
pid,sid相互查找:
v$session_wait
v$session
v$sqltext
v$process
///////pid找到sid///////// (假如进程找不到,那就不是oracle的进程)////
/////sid找到pid///////////(可能其他导致的)
补充1:
根据pid找到sql语句
SELECT
sql_text,hash_value
FROM v$sqltext a
WHERE (a.hash_value, a.address) IN (
SELECT DECODE (sql_hash_value,
0, prev_hash_value,
sql_hash_value
),
DECODE (sql_hash_value, 0, prev_sql_addr, sql_address)
FROM v$session b
WHERE b.paddr = (SELECT addr
FROM v$process c
WHERE c.spid = '&pid'))
ORDER BY piece ASC
补充2:
根据pid,找到sid,serial#,再删除
select sid,serial# FROM v$session b
WHERE b.paddr = (SELECT addr
FROM v$process c
WHERE c.spid = '&pid')
ORDER BY piece ASC
说明: 这里的v$process的spid-就是top中的pid
补充3:
根据sid,serial#,找到PID=
Select c.spid from v$process c where c.addr=(select b.paddr from v$session b where b.sid= ' ' and b.serial#= ' ')
分享标题:pid,sid相互查找,根据PID查询sql
转载来源:
http://cdweb.net/article/ghpicg.html