SYS_CONTEXT ФУНКЦИЯ

В этом учебном пособии вы узнаете, как использовать Oracle/PLSQL функцию SYS_CONTEXT с синтаксисом и примерами.

Описание

Oracle/PLSQL функция SYS_CONTEXT используется для получения информации о состоянии среды окружения Oracle.

Синтаксис

Синтаксис Oracle/PLSQL функции SYS_CONTEXT:

SYS_CONTEXT( namespace, parameter, [ length ] )

Параметры или аргументы

namespace — пространство имен Oracle, которое уже было создано. Если пространство имен ‘USERENV’ используется, могут быть возвращены атрибуты описания текущей сессии Oracle.

parameter — допустимый атрибутом, который был установлен с помощью процедуры DBMS_SESSION.SET_CONTEXT.

length — необязательный. Это длина возвращаемого значения в байтах. Если этот параметр не указан или если недопустимый ввод, функция SYS_CONTEXT по умолчанию будет 256 байт.

Примечание

Допустимые параметры для пространства имен ‘USERENV’: (Обратите внимание, что не все параметры действительны во всех версиях Oracle)

ParameterExplanationOracle 9iOracle 10gOracle 11g
ACTIONReturns the position in the moduleNoYesYes
AUDITED_CURSORIDReturns the cursor ID of the SQL that triggered the auditYesYesYes
AUTHENTICATED_IDENTITYReturns the identity used in authenticationNoYesYes
AUTHENTICATION_DATAAuthentication dataYesYesYes
AUTHENTICATION_METHODReturns the method of authenticationNoYesYes
AUTHENTICATION_TYPEDescribes how the user was authenticated. Can be one of the following values: Database, OS, Network, or ProxyYesNoNo
BG_JOB_IDIf the session was established by an Oracle background process, this parameter will return the Job ID. Otherwise, it will return NULL.YesYesYes
CLIENT_IDENTIFIERReturns the client identifier (global context)YesYesYes
CLIENT_INFOUser session informationYesYesYes
CURRENT_BINDBind variables for fine-grained auditingNoYesYes
CURRENT_SCHEMAReturns the default schema used in the current schemaYesYesYes
CURRENT_SCHEMAIDReturns the identifier of the default schema used in the current schemaYesYesYes
CURRENT_SQLReturns the SQL that triggered the audit eventYesYesYes
CURRENT_SQL_LENGTHReturns the length of the current SQL statement that triggered the audit eventNoYesYes
CURRENT_USERName of the current userYesNoNo
CURRENT_USERIDUserid of the current userYesNoNo
DB_DOMAINDomain of the database from the DB_DOMAIN initialization parameterYesYesYes
DB_NAMEName of the database from the DB_NAME initialization parameterYesYesYes
DB_UNIQUE_NAMEName of the database from the DB_UNIQUE_NAME initialization parameterNoYesYes
ENTRYIDAvailable auditing entry identifierYesYesYes
ENTERPRISE_IDENTITYReturns the user’s enterprise-wide identityNoYesYes
EXTERNAL_NAMEExternal of the database userYesNoNo
FG_JOB_IDIf the session was established by a client foreground process, this parameter will return the Job ID. Otherwise, it will return NULL.YesYesYes
GLOBAL_CONTEXT_MEMORYThe number used in the System Global Area by the globally accessed contextYesYesYes
GLOBAL_UIDThe global user ID from Oracle Internet Directory for enterprise security logins. Returns NULL for all other logins.NoNoYes
HOSTName of the host machine from which the client has connectedYesYesYes
IDENTIFICATION_TYPEReturns the way the user’s schema was createdNoYesYes
INSTANCEThe identifier number of the current instanceYesYesYes
INSTANCE_NAMEThe name of the current instanceNoYesYes
IP_ADDRESSIP address of the machine from which the client has connectedYesYesYes
ISDBAReturns TRUE if the user has DBA privileges. Otherwise, it will return FALSE.YesYesYes
LANGThe ISO abbreviate for the languageYesYesYes
LANGUAGEThe language, territory, and character of the session. In the following format: language_territory.charactersetYesYesYes
MODULEReturns the appplication name set through DBMS_APPLICATION_INFO package or OCINoYesYes
NETWORK_PROTOCOLNetwork protocol usedYesYesYes
NLS_CALENDARThe calendar of the current sessionYesYesYes
NLS_CURRENCYThe currency of the current sessionYesYesYes
NLS_DATE_FORMATThe date format for the current sessionYesYesYes
NLS_DATE_LANGUAGEThe language used for datesYesYesYes
NLS_SORTBINARY or the linguistic sort basisYesYesYes
NLS_TERRITORYThe territory of the current sessionYesYesYes
OS_USERThe OS username for the user logged inYesYesYes
POLICY_INVOKERThe invoker of row-level security policy functionsNoYesYes
PROXY_ENTERPRISE_IDENTITYThe Oracle Internet Directory DN when the proxy user is an enterprise userNoYesYes
PROXY_GLOBAL_UIDThe global user ID from Oracle Internet Directory for enterprise user security proxy users. Returns NULL for all other proxy users.NoYesYes
PROXY_USERThe name of the user who opened the current session on behalf of SESSION_USERYesYesYes
PROXY_USERIDThe identifier of the user who opened the current session on behalf of SESSION_USERYesYesYes
SERVER_HOSTThe host name of the machine where the instance is runningNoYesYes
SERVICE_NAMEThe name of the service that the session is connected toNoYesYes
SESSION_USERThe database user name of the user logged inYesYesYes
SESSION_USERIDThe database identifier of the user logged inYesYesYes
SESSIONIDThe identifier of the auditing sessionYesYesYes
SIDSession numberNoYesYes
STATEMENTIDThe auditing statement identifierNoYesYes
TERMINALThe OS identifier of the current sessionYesYesYes

Применение

Функцию SYS_CONTEXT можно использовать в следующих версиях Oracle/PLSQL:

  • Oracle 12c, Oracle 11g, Oracle 10g, Oracle 9i, Oracle 8i

Пример

Рассмотрим несколько примеров функции Oracle SYS_CONTEXT и изучим, как использовать функцию SYS_CONTEXT в Oracle/PLSQL.