Oracle System Function - Oracle/PLSQL SYS_CONTEXT Function






This Oracle tutorial explains how to use the Oracle/PLSQL SYS_CONTEXT function.

The Oracle/PLSQL SYS_CONTEXT function can be used to retrieve information about the Oracle environment.

Syntax

The syntax for the Oracle/PLSQL SYS_CONTEXT function is:

SYS_CONTEXT( namespace, parameter, [ length ] )

namespace is an Oracle namespace. If the namespace of 'USERENV' is used, attributes describing the current Oracle session can be returned.

parameter is an attribute set with the DBMS_SESSION.set_context procedure.

length is optional. It is the length of the return value in bytes. Default to 256 bytes.

The valid parameters for the namespace called 'USERENV' are as follows:

ParameterExplanation
ACTION Position in the module
AUDITED_CURSORID Cursor ID of the SQL that triggered the audit
AUTHENTICATED_IDENTITY Identity used in authentication
AUTHENTICATION_DATA Authentication data
AUTHENTICATION_METHOD method of authentication
AUTHENTICATION_TYPE Describes how the user was authenticated:Database, OS, Network, or Proxy
BG_JOB_ID If the session was established by an Oracle background process, this parameter will return the Job ID. Otherwise, it will return NULL.
CLIENT_IDENTIFIER Returns the client identifier (global context)
CLIENT_INFO User session information
CURRENT_BIND Bind variables for fine-grained auditing
CURRENT_SCHEMA Returns the default schema used in the current schema
CURRENT_SCHEMAID Returns the identifier of the default schema used in the current schema
CURRENT_SQL Returns the SQL that triggered the audit event
CURRENT_SQL_LENGTH Returns the length of the current SQL statement that triggered the audit event
CURRENT_USER Name of the current user
CURRENT_USERID Userid of the current user
DB_DOMAIN Domain of the database from the DB_DOMAIN initialization parameter
DB_NAME Name of the database from the DB_NAME initialization parameter
DB_UNIQUE_NAME Name of the database from the DB_UNIQUE_NAME initialization parameter
ENTRYID Auditing entry identifier
ENTERPRISE_IDENTITY User's enterprise-wide identity
EXTERNAL_NAME External of the database user
FG_JOB_ID Return the Job ID, if the session was established by a client foreground process. Otherwise, it will return NULL.
GLOBAL_CONTEXT_MEMORY The number used in the System Global Area by the globally accessed context
GLOBAL_UID Global user ID from Oracle Internet Directory for enterprise security logins. Returns NULL for all other logins.
HOST Name of the host machine from which the client has connected
IDENTIFICATION_TYPE The way the user's schema was created
INSTANCE The identifier number of the current instance
INSTANCE_NAME The name of the current instance
IP_ADDRESS IP address of the machine from which the client has connected
ISDBA Returns TRUE if the user has DBA privileges. Otherwise, it will return FALSE.
LANG The ISO abbreviate for the language
LANGUAGE The language, territory, and character of the session. In the following format:
language_territory.characterset
MODULE Returns the appplication name set through DBMS_APPLICATION_INFO package or OCI
NETWORK_PROTOCOL Network protocol used
NLS_CALENDAR The calendar of the current session
NLS_CURRENCY The currency of the current session
NLS_DATE_FORMAT The date format for the current session
NLS_DATE_LANGUAGE The language used for dates
NLS_SORT BINARY or the linguistic sort basis
NLS_TERRITORY The territory of the current session
OS_USER The OS username for the user logged in
POLICY_INVOKER The invoker of row-level security policy functions
PROXY_ENTERPRISE_IDENTITY The Oracle Internet Directory DN when the proxy user is an enterprise user
PROXY_GLOBAL_UID The global user ID from Oracle Internet Directory for enterprise user security proxy users. Returns NULL for all other proxy users.
PROXY_USER The name of the user who opened the current session on behalf of SESSION_USER
PROXY_USERID The identifier of the user who opened the current session on behalf of SESSION_USER
SERVER_HOST The host name of the machine where the instance is running
SERVICE_NAME The name of the service that the session is connected to
SESSION_USER The database user name of the user logged in
SESSION_USERID The database identifier of the user logged in
SESSIONID The identifier of the auditing session
SID Session number
STATEMENTID The auditing statement identifier
TERMINAL The OS identifier of the current session




Example

SYS_CONTEXT('USERENV', 'NLS_DATE_FORMAT')
----------------------------------------
                               'RR-MM-DD'
 
SYS_CONTEXT('USERENV', 'NLS_SORT')
---------------------------------
                          'BINARY'