Purpose
This function returns information about the current session. This function cannot be used in CHECK constraints.
Syntax
USERENV('parameter')
Parameters
The parameter argument can be one of the following values:
| Value | Description |
|---|---|
| CLIENT_INFO | Returns user session information (up to 64 bytes). Applications can use the DBMS_APPLICATION_INFO system package to store this information. |
| INSTANCE | The identifier of the current instance. |
| LANG | The abbreviation of the language, which is a shorter format than the LANGUAGE parameter. |
| LANGUAGE | The language, territory, and character set used by the current session. The format is language_territory.characterset. |
| SCHEMAID | The schema ID. |
| SID | SESSIONID | Returns the Client Session ID of the current session. This ID uniquely identifies the session in the client. |
Return value
Except for calls with the SESSIONID and SID parameters, which return a NUMBER, other parameters return a VARCHAR2 data type.
Examples
Obtain the language, territory, and character set used by the current session.
obclient [SYS]> SELECT USERENV('LANGUAGE') "Language" FROM DUAL;The result is as follows:
+---------------------------+ | Language | +---------------------------+ | AMERICAN_AMERICA.AL32UTF8 | +---------------------------+ 1 row in setObtain the schema ID of the current session.
obclient [SYS]> SELECT USERENV('SCHEMAID') FROM DUAL;The result is as follows:
+---------------------+ | USERENV('SCHEMAID') | +---------------------+ | 201006 | +---------------------+ 1 row in setObtain the Client Session ID of the current session.
obclient [SYS]> SELECT USERENV('SESSIONID') AS Client_Session_ID FROM DUAL;or
obclient [SYS]> SELECT USERENV('SID') AS Client_Session_ID FROM DUAL;The result is as follows:
+-------------------+ | CLIENT_SESSION_ID | +-------------------+ | 3221488033 | +-------------------+ 1 row in set
References
You can also query the number of sessions and their IDs in the current database by using the SHOW PROCESSLIST statement. For more information, see View tenant sessions.
