Skip to content

SYS_CONTEXT

SYS_CONTEXT(‘namespace_string’, ‘parameter_string’)

Section titled “SYS_CONTEXT(‘namespace_string’, ‘parameter_string’)”
  • ‘namespace_string’: This parameter specifies the namespace. A namespace is an environment or domain that the user-defined parameter belongs to. SYS_CONTEXT requires ‘namespace_string’ to evaluate user-defined parameters.
  • ‘parameter_string’: This parameter specifies the parameter, the attribute within the namespace you are looking to retrieve. These parameters could be predefined by the system or user-defined. The ‘parameter_string’ within SYS_CONTEXT will return the value of the specified parameter.
SELECT SYS_CONTEXT('USERENV', 'SESSION_USER') FROM DUAL;
SYS_CONTEXT('USERENV','SESSION_USER')
------------------------------------
SCOTT

The SYS_CONTEXT function is a very flexible function in Oracle that allows you to retrieve information about the Oracle environment. The above example shows how to use the SYS_CONTEXT function to get the current session user. The 'USERENV' parameter is a built-in namespace in Oracle that includes a variety of useful information about the user and session context. The 'SESSION_USER' attribute represents the name of the user that initiated the current session.