Purpose
SYS_CONTEXT() returns the value of a parameter that is currently associated with the context namespace.
Syntax
SYS_CONTEXT('namespace', 'parameter' [, length ])
Parameters
| Parameter | Description |
|---|---|
| namespace | The namespace. Currently, only USERENV is supported. |
| parameter | The parameter associated with the namespace. For more information about supported parameters, see the predefined parameters of the USERENV namespace in the following table. |
| length | The length of the return value, in bytes. This parameter is optional. Value range: [1, 4000]. Default value: 256. |
Predefined parameters of the USERENV namespace
| Parameter | Return value |
|---|---|
| CON_ID | If queried while connected to a container database (CDB), returns the current container ID. Otherwise, returns 0. |
| CON_NAME | If queried while connected to a CDB, returns the current container name. Otherwise, returns the name of the database specified by DB_NAME. |
| CURRENT_SCHEMA | The name of the current active schema. |
| CURRENT_SCHEMAID | The ID of the current active schema. |
| CURRENT_USER | The name of the database user whose privileges are currently active. |
| CURRENT_USERID | The ID of the database user whose privileges are currently active. |
| DB_NAME | The name of the database. |
| INSTANCE | The ID of the current instance. |
| INSTANCE_NAME | The name of the current instance. |
| IP_ADDRESS | The IP address of the client. |
| LANG | The abbreviated name of the language, which is shorter than LANGUAGE. |
| LANGUAGE | The language, region, and database character set of the current session. |
| SESSION_USER | The name of the logged-on database user, which remains unchanged during the session. |
| SESSION_USERID | The ID of the logged-on database user. |
| SID | SESSIONID | The client session ID of the current session, which is the unique identifier of a session in a client. |
Return type
The return type is VARCHAR2.
Examples
View the client session ID in the USERENV namespace.
obclient [SYS]> SELECT SYS_CONTEXT ('USERENV', 'SESSIONID') AS Client_Session_ID FROM DUAL;
or
obclient [SYS]> SELECT SYS_CONTEXT ('USERENV', 'SID') AS Client_Session_ID FROM DUAL;
The return result is as follows:
+-------------------+
| CLIENT_SESSION_ID |
+-------------------+
| 3221488043 |
+-------------------+
1 row in set
References
You can execute the SHOW PROCESSLIST statement to query the quantity and IDs of sessions in the current database. For more information, see View tenant sessions.