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. Supports the USERENV namespace as well as any custom-built namespaces. |
| 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. |
The following table describes the predefined parameters of the USERENV namespace.
| Parameter | Description |
|---|---|
| CON_ID | The current container ID is returned when the database specified by DB_NAME is connected to a container database (CDB). Otherwise, 0 is returned. |
| CON_NAME | The current container name is returned when the database specified by DB_NAME is connected to a CDB. Otherwise, the name of the database specified by DB_NAME is returned. |
| 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 the value of LANGUAGE. |
| LANGUAGE | The language, region, and database character set of the current session. |
| SESSION_USER | The name of the logged-in database user, which remains unchanged during the session. |
| SESSION_USERID | The ID of the logged-in database user. |
| SID | SESSIONID | The client session ID of the current session, which is the unique identifier of the session in the 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.