Get Sid and Serial # My Session

DBA Geral (instalação, configuração do banco, scripts do Sql*Plus, shell scripts, batch scripts, etc...)
Post Reply
claudio.alexandre
Rank: Estagiário Júnior
Rank: Estagiário Júnior
Posts: 1
Joined: Fri, 19 Aug 2011 5:27 pm
Location: Anápolis

Good afternoon,
I need your help. I need to identify which and the SID and Serial # of my session in Oracle.

Environment information:
* Oracle version: 11g XE and Standart
* Operating system: Windows and Linux
User avatar
stcoutinho
Moderador
Moderador
Posts: 850
Joined: Wed, 11 May 2011 5:15 pm
Location: são Paulo - SP

Claudio,

You can use to resolve your problem the USERENV function, which exists since the Oracle 8i version.

The syntax of this function would be:



The parameter would be the value returned by the Oracle's current session. Some information you could get with this function are:

Select all

CLIENT_INFO [ex: USERNEV('CLIENT_INFO')] : Retorna o valor da coluna CLIENT_INFO da V$SESSION; 
INSTANCE    [ex: USERNEV('CLIENT_INFO')] : O número de identificação da Instância Oracle; 
ISDBA       [ex: USERNEV('ISDBA')      ] : Se o usuário corrente tem privilégios de DBA (TRUE/FALSE); 
LANG        [ex: USERNEV('LANG')       ] : O código ISO abreviado do idioma; 
LANGUAGE    [ex: USERNEV('LANGUAGE')   ] : Informações sobre idioma/território; 
SESSIONID   [ex: USERNEV('SESSIONID')  ] : Corresponde à coluna AUDSID da V$SESSION; 
TERMINAL    [ex: USERNEV('TERMINAL')   ] : Nome do terminal/computador que está se conectando no banco;
Combining this function with V $ Session Vista, which presents the bank's session ratio, You can get the SID and Serial # from the user's current session with the following criar:

Select all

SELECT sid, 
            serial# 
   FROM v$session 
WHERE audsid=USERENV('SESSIONID');
I found in the Oracle documentation that the USERENV function is obsolete and which is only maintained in Oracle for compatibility purposes.

They recommend that using the SYS_Context function, which offers a much greater range of information to the developer.

If you are interested in knowing the SYS_Context function, you can consult the link: http://www.techonthenet.com/oracle/func ... ontext.php
Hugs,

Sergio Coutinho
Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 1 guest