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 name | 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. |
| SESSIONID | The auditing session ID. |
| 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 | The session ID. |
Return type
The return type is VARCHAR2.
Examples
View the session ID in the USERENV namespace.
obclient> SELECT SYS_CONTEXT ('USERENV', 'SID') FROM DUAL;
+------------------------------+
| SYS_CONTEXT('USERENV','SID') |
+------------------------------+
| 3221638765 |
+------------------------------+
1 row in set