Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1216
  • Last Modified:

SID of current session?

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
rtieland
Asked:
rtieland
  • 3
  • 3
  • 2
  • +1
1 Solution
 
hayrabedianCommented:
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
 
rtielandAuthor Commented:
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
 
M-AliCommented:
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
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
hayrabedianCommented:
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
 
M-AliCommented:
NO hayrabedian, they are different. Try it.

Ali
0
 
dash420Commented:
select user , global_name,
          USERENV('TERMINAL') terminal,USERENV('SESSIONID') sessionid
   from   global_name
0
 
dash420Commented:
select user , global_name,
          USERENV('TERMINAL') terminal,USERENV('SESSIONID') sessionid
   from   global_name
0
 
hayrabedianCommented:
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
 
dash420Commented:
SELECT USERNAME, SID, SERIAL#, PROGRAM FROM V$SESSION
WHERE AUDSID = USERENV('SESSIONID')
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now