Solved

SID of current session?

Posted on 2002-07-29
9
1,208 Views
Last Modified: 2012-05-04
Hi,

how do i get the current SID for the user connected to the Oracle database.

i know this can be done with mssql by the command @@SPID, what is the equivalent in oracle?

thanks in advance,
ruben
0
Comment
Question by:rtieland
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 3

Expert Comment

by:hayrabedian
ID: 7184779
Hi, if your user has enough privileges you can use:

SELECT SID
  FROM v$session
 WHERE username = user;

Note: this will return all session IDs for the current user.
0
 
LVL 1

Author Comment

by:rtieland
ID: 7184796
Hi hayrabedian,

your solution doesn't work for me because there can be multiple sessions with the same username.

thanks though for your quick reply,
ruben
0
 
LVL 6

Accepted Solution

by:
M-Ali earned 50 total points
ID: 7184800
Yes, you are right. You need to use:

SELECT sid FROM V$SESSION WHERE audsid = USERENV('SESSIONID');

If user does not have the priviledge, you can grant the rights when connected as SYS user:

GRANT SELECT ON V_$SESSION TO user;

HTH
Ali
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 3

Expert Comment

by:hayrabedian
ID: 7184809
Hi,

yes the solution from Ali is the right one :)
Just one detail:

You can use just:
SELECT USERENV('SESSIONID') FROM DUAL;

And no privileges are needed.
0
 
LVL 6

Expert Comment

by:M-Ali
ID: 7184820
NO hayrabedian, they are different. Try it.

Ali
0
 
LVL 6

Expert Comment

by:dash420
ID: 7184821
select user , global_name,
          USERENV('TERMINAL') terminal,USERENV('SESSIONID') sessionid
   from   global_name
0
 
LVL 6

Expert Comment

by:dash420
ID: 7184823
select user , global_name,
          USERENV('TERMINAL') terminal,USERENV('SESSIONID') sessionid
   from   global_name
0
 
LVL 3

Expert Comment

by:hayrabedian
ID: 7184847
Hi,

Ali is right again:) I don't know why the "Auditing session ID" is returned by the USERENV('SESSIONID'), but we have to live with that.

Best regards,
Eddie
0
 
LVL 6

Expert Comment

by:dash420
ID: 7184882
SELECT USERNAME, SID, SERIAL#, PROGRAM FROM V$SESSION
WHERE AUDSID = USERENV('SESSIONID')
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
su - oracle could not open session 6 95
Retreiving column names in Windows but not in Unix 11 57
ODBC in excel 2016 in Windows 10 via VBA 16 135
Sybase and replication server 13 38
Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question