?
Solved

SID of current session?

Posted on 2002-07-29
9
Medium Priority
?
1,212 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 200 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: http://www.e-e.com/A_8429.html Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many‚Ķ
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 how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Suggested Courses

801 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