Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

SID of current session?

Posted on 2002-07-29
9
Medium Priority
?
1,213 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

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.

Question has a verified solution.

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

Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

618 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