问题
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