Session ID of a sql query

流过昼夜 提交于 2019-12-13 18:18:12

问题


How can I know the session ID of a sql query? If I have an SELECT query running, then how acn I know the session ID of that sql query?


回答1:


Assuming Oracle from your question history;

select sys_context('USERENV', 'SID') from dual



回答2:


on Oracle, this query gives you some useful details about the active SQLs

SELECT sa.sql_id,
       sa.sql_text                      txt,
       ''''||sid||', '||s.serial#||'''' sid_serial,
       pid,
       process                          client_pid,
       p.spid                           spid,
       blocking_session,
       BLOCKING_SESSION_STATUS,
       S.seconds_in_wait,
       s.program
  FROM V$PROCESS p,
       V$SESSION s,
       V$SQLAREA sa
 WHERE p.addr=s.paddr
   AND s.username IS NOT NULL
   AND s.sql_address=sa.address(+)
   AND s.sql_hash_value=sa.hash_value(+)
   AND s.status = 'ACTIVE'
 ORDER BY sid;


来源:https://stackoverflow.com/questions/9565952/session-id-of-a-sql-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!