SYS_CONTEXT

Returns information about the current session.

The data type of the return value is VARCHAR2.

SQL syntax

SYS_CONTEXT('namespace', 'parameter' [, length ])

Parameters

SYS_CONTEXT has the parameters:

Parameter Description

namespace

Value: USERENV

Other values result in a return of NULL.

parameter

Supported values:

  • ACTION

  • AUTHENTICATION_METHOD

  • CLIENT_INFO

  • CURRENT_SCHEMA

  • CURRENT_USER

  • CURRENT_USERID

  • IDENTIFICATION_TYPE

  • LANG

  • LANGUAGE

  • MODULE

  • NLS_SORT

  • SESSION_USER

  • SESSION_USERID

  • SID

length

Length in bytes, from 1 to 4000.

These are descriptions of the supported values for parameter:

Parameter Description

ACTION

Identifies the position in the module (application name) and is set through OCI.

AUTHENTICATION_METHOD

Returns the method of authentication for these types of users:

  • Local database user authenticated by password

  • External user authenticated by the operating system

CLIENT_INFO

Returns the user session information that can be stored by an application through OCI.

CURRENT_SCHEMA

The name of the currently active database schema. This may change during the duration of a session to reflect the owner of any active definer's rights object. When used directly in the body of a view definition, this returns the default schema used when executing the SQL statement that is using the view. It does not respect views used in the SQL statement as having definer's rights.

SYS_CONTEXT returns the same value when the CURRENT_SCHEMA parameter is supplied as it does when the CURRENT_USER parameter is supplied.

CURRENT_USER

The name of the database user whose privileges are currently active. This may change during the duration of a session to reflect the owner of any active definer's rights object. When no definer's rights object is active, CURRENT_USER returns the same value as SESSION_USER. When used directly in the body of a view definition, this returns the user that is executing the SQL statement that is using the view. It does not respect views used in the SQL statement as having definer's rights.

CURRENT_USERID

The identifier of the database user whose privileges are currently active.

IDENTIFICATION_TYPE

Returns the way the user was created in the database. Specifically, it reflects the IDENTIFIED clause in the CREATE/ALTER USER syntax. In the list that follows, the syntax used during user creation is followed by the identification type returned:

  • IDENTIFIED BY password: LOCAL

  • IDENTIFIED EXTERNALLY: EXTERNAL

LANG

The ISO abbreviation for the language name, a shorter form than the existing 'LANGUAGE' parameter.

LANGUAGE

The language and territory currently used by the session, along with the database character set, in this form:

language_territory.characterset

MODULE

The application name (module) set through OCI.

NLS_SORT

Binary or linguistic sort.

SESSION_USER

The name of the database user at logon. This value remains the same throughout the duration of the session.

SESSION_USERID

The identifier of the database user at logon.

SID

The connection ID of the current connection.

Description

The data type of the return value is VARCHAR2.

Examples

SELECT SYS_CONTEXT('USERENV', 'CURRENT_USER') FROM dual;
< TERRY >
1 row found.

SELECT SYS_CONTEXT('USERENV', 'LANGUAGE') FROM dual;
< AMERICAN_AMERICA.AL32UTF8 >
1 row found.

SELECT SYS_CONTEXT('USERENV', 'IDENTIFICATION_TYPE') FROM dual;
< EXTERNAL >
1 row found.