Solved

SID of current session?

Posted on 2002-07-29
9
1,202 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
 
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
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 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.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
oracle 10G 5 48
Oracle PL/SQL syntax 4 52
Concat multi row values of a field in oracle 6 41
Oracle and DateTime math 6 16
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…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now