Ashish Anand
Ashish Anand

Reputation: 3581

Session ID of a sql query

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?

Upvotes: 1

Views: 17787

Answers (2)

mcha
mcha

Reputation: 2998

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;

Upvotes: 1

Alex K.
Alex K.

Reputation: 175876

Assuming Oracle from your question history;

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

Upvotes: 1

Related Questions