Oracle SYS_CONTEXT
Version 12.1.0.1

General Information
Library Note Morgan's Library Page Footer
The Library is currently in the process of being upgraded from Oracle Database Version 11.2.0.3 to 12.1.0.1. Demos are being upgraded to reflect the new Container paradigm as well as EBR (Edition Based Redefinition) and may contain references to CDBs, PDBs, and other objects you may not be familiar with such as CDB_OBJECTS_AE: Welcome to 12c.
Note: USERENV is an Oracle provided namespace that describes the current session.
Data Dictionary Objects
DBA_EDITION V$PARAMETER V$SESSION
V$DATABASE    
Syntax SELECT sys_context('<namespace>', '<parameter>', <length>)
FROM dual;

SYS_CONTEXT(namespace IN VARCHAR2, attribute IN VARCHAR2)
RETURN VARCHAR;

SYS_CONTEXT(namespace IN VARCHAR2, attribute IN VARCHAR2, newoptional IN VARCHAR2)
RETURN VARCHAR2;
 
ACTION
Retrieves the value for the current session from v$session.action SYS_CONTEXT('USERENV', 'ACTION')
SELECT sys_context('USERENV', 'ACTION') FROM dual;

exec dbms_application_info.set_action('INSERTING');

SELECT sys_context('USERENV', 'ACTION') FROM dual;
 
AUDITED_CURSORID
Returns the cursor ID of the SQL that triggered the audit. Will return NULL with FGA. SYS_CONTEXT('USERENV', 'AUDITED_CURSORID')
SELECT sys_context('USERENV', 'AUDITED_CURSORID') FROM dual;
 
AUTHENTICATED_IDENTITY
Returns the identity used in logon authentication SYS_CONTEXT('USERENV', 'AUTHENTICATED_IDENTITY')
SELECT sys_context('USERENV', 'AUTHENTICATED_IDENTITY') FROM dual;

SYS_CONTEXT('USERENV','AUTHENTICATED_IDENTITY')
-----------------------------------------------
uwclass
 
AUTHENTICATION_DATA
Data being used to authenticate the login user. For X.503 sessions, returns the context of the certificate in HEX2 format. SYS_CONTEXT('USERENV', 'AUTHENTICATION_DATA')
SELECT sys_context('USERENV', 'AUTHENTICATION_DATA') FROM dual;
 
AUTHENTICATION_METHOD
Returns the method of authentication SYS_CONTEXT('USERENV', 'AUTHENTICATION_METHOD')
SELECT sys_context('USERENV', 'AUTHENTICATION_METHOD') FROM dual;

SYS_CONTEXT('USERENV','AUTHENTICATION_METHOD')
----------------------------------------------
PASSWORD
 
BG_JOB_ID
Job ID of the current session if it was established by an Oracle background process, else NULL SYS_CONTEXT('USERENV', 'BG_JOB_ID')
SELECT sys_context('USERENV', 'BG_JOB_ID') FROM dual;
 
CDB_NAME (new 12.1)
Name of the container database SYS_CONTEXT('USERENV', 'CDB_NAME')
SELECT sys_context('USERENV', 'CDB_NAME') FROM dual;

SYS_CONTEXT('USERENV','CDB_NAME')
---------------------------------------------------------
orabeta
 
CLIENT_IDENTIFIER
Returns an identifier set by DBMS_SESSION.SET_IDENTIFIER. Can be used by to identify lightweight application users who authenticate as the same user. SYSCONTEXT('USERENV', 'CLIENT_IDENTIFIER')
SELECT sys_context('USERENV', 'CLIENT_IDENTIFIER') FROM dual;

exec dbms_session.set_identifier(USER || ' ' || SYSTIMESTAMP);

SELECT sys_context('USERENV', 'CLIENT_IDENTIFIER') FROM dual;
 
CLIENT_INFO
Returns the value from v$session.client_info that can bet set using DBMS_APPLICATION_INFO SYSCONTEXT('USERENV', 'CLIENT_INFO')
SELECT sys_context('USERENV', 'CLIENT_INFO') FROM dual;

exec dbms_application_info.set_client_info('TEST');

SELECT sys_context('USERENV', 'CLIENT_INFO') FROM dual;
 
CLIENT_PROGRAM_NAME (new 12.1)
Name of the program used for the database session SYSCONTEXT('USERENV', 'CLIENT_PROGRAM_NAME')
-- connect to root db
conn / as sysdba

SELECT sys_context('USERENV', 'CLIENT_PROGRAM_NAME') FROM dual;

SYS_CONTEXT('USERENV','CLIENT_PROGRAM_NAME')
---------------------------------------------
sqlplus.exe
 
CON_ID (new 12.1)
Container Identifier SYSCONTEXT('USERENV', 'CON_ID')
-- connect to root db
conn / as sysdba

SELECT sys_context('USERENV', 'CON_ID') FROM dual;

SYS_CONTEXT('USERENV','CON_ID')
-------------------------------
1
 
CON_NAME (new 12.1)
Container name SYSCONTEXT('USERENV', 'CON_NAME')
-- connect to root db
conn / as sysdba

SELECT sys_context('USERENV', 'CON_NAME') FROM dual;

SYS_CONTEXT('USERENV','CON_NAME')
---------------------------------
CDB$ROOT

-- connect to pluggable database
conn uwclass/uwclass@orabase

SYS_CONTEXT('USERENV','CON_NAME')
---------------------------------
ORABASE
 
CURRENT_BIND
The bind variables for fine-grained auditing SYSCONTEXT('USERENV', 'CURRENT_BIND')
TBD
 
CURRENT_EDITION_ID
The numeric identifier of the current edition SYSCONTEXT('USERENV', 'CURRENT_EDITION_ID')
SELECT sys_context('USERENV', 'CURRENT_EDITION_ID') FROM dual;

SYS_CONTEXT('USERENV','CURRENT_EDITION_ID')
--------------------------------------------
131
 
CURRENT_EDITION_NAME
The name of the current edition SYSCONTEXT('USERENV', 'CURRENT_EDITION_NAME')
SELECT sys_context('USERENV', 'CURRENT_EDITION_NAME') FROM dual;

SYS_CONTEXT('USERENV','CURRENT_EDITION_NAME')
---------------------------------------------
ORA$BASE
 
CURRENT_SCHEMA
Name of the default schema being used in the current schema. This value can be changed during the session with an ALTER SESSION SET CURRENT_SCHEMA statement. SYSCONTEXT('USERENV', 'CURRENT_SCHEMA')
SELECT sys_context('USERENV', 'CURRENT_SCHEMA') FROM dual;

SYS_CONTEXT('USERENV','CURRENT_SCHEMA')
---------------------------------------
UWCLASS
 
CURRENT_SCHEMAID
Identifier of the default schema being used in the current session SYSCONTEXT('USERENV', 'CURRENT_SCHEMAID')
SELECT sys_context('USERENV', 'CURRENT_SCHEMAID') FROM dual;

SYS_CONTEXT('USERENV','CURRENT_SCHEMAID')
-----------------------------------------
102

SELECT user#
FROM sys.user$
WHERE name = USER;
 
CURRENT_SQL
Returns the first 4K bytes of the current SQL that triggered the fine-grained auditing event SYSCONTEXT('USERENV', 'CURRENT_SQL')
TBD
 
CURRENT_SQLn
CURRENT_SQLn attributes return subsequent 4K-byte increments, where n can be an integer from 1 to 7, inclusive SYSCONTEXT('USERENV', 'CURRENT_SQLn')
TBD
 
CURRENT_SQL_LENGTH
The length of the current SQL that triggers fine-grained audit or row-level security (RLS) policy functions or event handlers where it is located SYSCONTEXT('USERENV', 'CURRENT_SQL_LENGTH')
TBD
 
CURRENT_USER
The name of the database user whose privileges are currently active SYSCONTEXT('USERENV', 'CURRENT_USER')
SELECT sys_context('USERENV', 'CURRENT_USER') FROM dual;

SYS_CONTEXT('USERENV','CURRENT_USER')
-------------------------------------
UWCLASS
 
CURRENT_USERID
The identifier of the database user whose privileges are currently active SYSCONTEXT('USERENV', 'CURRENT_USERID')
SELECT sys_context('USERENV', 'CURRENT_USERID') FROM dual;

SYS_CONTEXT('USERENV','CURRENT_USERID')
---------------------------------------
102
 
DATABASE_ROLE
The database role is one of the following: PRIMARY, PHYSICAL STANDBY, LOGICAL STANDBY, SNAPSHOT STANDBY SYSCONTEXT('USERENV', 'DATABASE_ROLE')
SELECT sys_context('USERENV', 'DATABASE_ROLE') FROM dual;

SYS_CONTEXT('USERENV','DATABASE_ROLE')
--------------------------------------
PRIMARY
 
DB_DOMAIN
Domain of the database as specified in the DB_DOMAIN initialization parameter SYSCONTEXT('USERENV', 'DB_DOMAIN')
SELECT sys_context('USERENV', 'DB_DOMAIN') FROM dual;
 
DB_NAME
Name of the database as specified in the DB_NAME initialization parameter. SYSCONTEXT('USERENV', 'DB_NAME')
SELECT sys_context('USERENV', 'DB_NAME') FROM dual;

SYS_CONTEXT('USERENV','DB_NAME')
--------------------------------
orabeta

SELECT name, value
FROM gv$parameter
where name LIKE 'db%name';
 
DB_SUPPLEMENTAL_LOG_LEVEL (new 12.1)
If supplemental logging is enabled, returns a string containing the list of enabled supplemental logging levels. Possible values are: ALL_COLUMN, FOREIGN_KEY, MINIMAL, PRIMARY_KEY, PROCEDURAL, and UNIQUE_INDEX: Else NULL SYSCONTEXT('USERENV', 'CON_ID')
-- connect to root db
conn / as sysdba

SELECT sys_context('USERENV', 'DB_SUPPLEMENTAL_LOG_LEVEL')
FROM dual;

ALTER DATABASE ADD SUPPLEMENTAL LOG DATA;

SELECT sys_context('USERENV', 'DB_SUPPLEMENTAL_LOG_LEVEL')
FROM dual;

SYS_CONTEXT('USERENV','DB_SUPPLEMENTAL_LOG_LEVEL')
--------------------------------------------------
MINIMAL
 
DB_UNIQUE NAME
Name of the database as specified in the DB_UNIQUE_NAME initialization parameter SYSCONTEXT('USERENV', 'DB_UNIQUE_NAME')
SELECT sys_context('USERENV', 'DB_UNIQUE_NAME') FROM dual;

SYS_CONTEXT('USERENV','DB_UNIQUE_NAME')
---------------------------------------
orabeta

SELECT name, value
FROM v$parameter
where name LIKE 'db%name';
 
DBLINK_INFO (new 12.1)
Returns the source of a DB_LINK session SYSCONTEXT('USERENV', 'DBLINK_INFO')
SELECT sys_context('USERENV', 'DBLINK_INFO') FROM dual;
 
ENTRYID
The available auditing entry identifier. You cannot use this option in distributed SQL statements. To use this keyword in USERENV, the initialization parameter AUDIT_TRAIL must be set to true. SYSCONTEXT('USERENV', 'ENTRYID')
SELECT sys_context('USERENV', 'ENTRYID') FROM dual;
 
ENTERPRISE_IDENTITY
Returns the user's enterprise-wide identity SYSCONTEXT('USERENV', 'ENTERPRISE_IDENTITY')
SELECT sys_context('USERENV', 'ENTERPRISE_IDENTITY') FROM dual;
 
FG_JOB_ID
Job ID of the current session if it was established by a client foreground proceselse NULL SYSCONTEXT('USERENV', 'FG_JOB_ID')
SELECT sys_context('USERENV', 'FG_JOB_ID') FROM dual;
 
GLOBAL_CONTEXT_MEMORY
The number used in the System Global Area by the globally accessed context SYSCONTEXT('USERENV', 'GLOBAL_CONTEXT_MEMORY')
SELECT sys_context('USERENV', 'GLOBAL_CONTEXT_MEMORY') FROM dual;
 
GLOBAL_UID
Returns the global user ID from Oracle Internet Directory for Enterprise User Security (EUS) login: Else NULL SYSCONTEXT('USERENV', 'GLOBAL_UID')
SELECT sys_context('USERENV', 'GLOBAL_UID') FROM dual;
 
HOST
Name of the host machine from which the client has connected SYSCONTEXT('USERENV', 'HOST')
SELECT sys_context('USERENV', 'HOST') FROM dual;

SYS_CONTEXT('USERENV','HOST')
-----------------------------
WORKGROUP\PERRITO4
 
IDENTIFICATION_TYPE
Returns the way the user's schema was created in the database. Specifically, the IDENTIFIED clause of the CREATE/ALTER USER DDL SYSCONTEXT('USERENV', 'IDENTIFICATION_TYPE')
SELECT sys_context('USERENV', 'IDENTIFICATION_TYPE') FROM dual;
 
INSTANCE
The instance identification number of the instance to which the session is connected SYSCONTEXT('USERENV', 'INSTANCE')
SELECT sys_context('USERENV', 'INSTANCE') FROM dual;
 
INSTANCE_NAME
The name of the instance to which the session is connected SYSCONTEXT('USERENV', 'INSTANCE_NAME')
SELECT sys_context('USERENV', 'INSTANCE_NAME') FROM dual;
 
IP_ADDRESS
IP address of the NIC from which the client is connected SYSCONTEXT('USERENV', 'IP_ADDRESS')
SELECT sys_context('USERENV', 'IP_ADDRESS') FROM dual;

SYS_CONTEXT('USERENV', 'IP_ADDRESS')
------------------------------------------------
141.204.244.96
 
IS_APPLY_SERVER (new 12.1)
Returns TRUE if queried from within a SQL Apply server in a logical standby database. Otherwise, returns FALSE SYSCONTEXT('USERENV', 'IS_APPLY_SERVER')
SELECT sys_context('USERENV', 'IS_APPLY_SERVER')
FROM dual;

SYS_CONTEXT('USERENV','IS_APPLY_SERVER')
----------------------------------------
FALSE
 
IS_DG_ROLLING_UPGRADE (new 12.1)
Returns TRUE if a rolling upgrade of the database software in a Data Guard configuration, initiated by way of the DBMS_ROLLING package, is active. Otherwise, returns FALSE. SYSCONTEXT('USERENV', 'IS_DG_ROLLING_UPGRADE')
SELECT sys_context('USERENV', 'IS_DG_ROLLING_UPGRADE')
FROM dual;

SYS_CONTEXT('USERENV','IS_DG_ROLLING_UPGRADE')
----------------------------------------------
FALSE
 
ISDBA
TRUE if the session is SYS SYSCONTEXT('USERENV', 'ISDBA')
SELECT sys_context('USERENV', 'ISDBA') FROM dual;
 
LANG
The ISO abbreviation for the language name, a shorter form than the existing 'LANGUAGE' parameter. SYSCONTEXT('USERENV', 'LANG')
SELECT sys_context('USERENV', 'LANG') FROM dual;
 
LANGUAGE
The language and territory currently used by your session, along with the database character set, in the form:
language_territory.characterset.
SYSCONTEXT('USERENV', 'LANGUAGE')
SELECT sys_context('USERENV', 'LANGUAGE') FROM dual;
 
MODULE
The application name (module) set through DBMS_APPLICATION_INFO SYSCONTEXT('USERENV', 'MODULE')
SELECT sys_context('USERENV', 'MODULE') FROM dual;
 
NETWORK_PROTOCOL
Network protocol being used for communication, as specified in the 'PROTOCOL=protocol' portion of the connect string SYSCONTEXT('USERENV', 'NETWORK_PROTOCOL')
SELECT sys_context('USERENV', 'NETWORK_PROTOCOL') FROM dual;

SYS_CONTEXT('USERENV', 'NETWORK_PROTOCOL')
------------------------------------------------
tcp
 
NLS_CALENDAR
The current calendar of the current session SYSCONTEXT('USERENV', 'NLS_CALENDAR')
SELECT sys_context('USERENV', 'NLS_CALENDAR') FROM dual;

SYS_CONTEXT('USERENV','NLS_CALENDAR')
-------------------------------------
GREGORIAN
 
NLS_CURRENCY
The currency of the current session SYSCONTEXT('USERENV', 'NLS_CURRENCY')
SELECT sys_context('USERENV', 'NLS_CURRENCY') FROM dual;

SYS_CONTEXT('USERENV','NLS_CURRENCY')
-------------------------------------
$
 
NLS_DATE_FORMAT
The date format for the session SYSCONTEXT('USERENV', 'NLS_DATE_FORMAT')
SELECT sys_context('USERENV', 'NLS_DATE_FORMAT') FROM dual;

SYS_CONTEXT('USERENV','NLS_DATE_FORMAT')
----------------------------------------
DD-MON-YYYY HH24:MI:SS
 
NLS_DATE_LANGUAGE
The language used for expressing dates SYSCONTEXT('USERENV', 'NLS_LANGUAGE')
SELECT sys_context('USERENV', 'NLS_DATE_LANGUAGE') FROM dual;

SYS_CONTEXT('USERENV','NLS_DATE_LANGUAGE')
------------------------------------------
AMERICAN
 
NLS_SORT
BINARY or the linguistic sort basis SYSCONTEXT('USERENV', 'NLS_SORT')
SELECT sys_context('USERENV', 'NLS_SORT') FROM dual;

SYS_CONTEXT('USERENV','NLS_SORT')
---------------------------------
BINARY
 
NLS_TERRITORY
The territory of the current session SYSCONTEXT('USERENV', 'NLS_TERRITORY')
SELECT sys_context('USERENV', 'NLS_TERRITORY') FROM dual;

SYS_CONTEXT('USERENV','NLS_TERRITORY')
--------------------------------------
AMERICA
 
ORACLE_HOME (new 12.1)
Returns the value of $ORACLE_HOME SYSCONTEXT('USERENV', 'ORACLE_HOME')
SELECT sys_context('USERENV', 'ORACLE_HOME')
FROM dual;

SYS_CONTEXT('USERENV','ORACLE_HOME')
-------------------------------------
c:\app\oracle\product\12.1.0\dbhome_1
 
OS_USER
Operating system username of the client process that initiated the database session SYSCONTEXT('USERENV', 'OS_USER')
SELECT sys_context('USERENV', 'OS_USER') FROM dual;

SYS_CONTEXT('USERENV','OS_USER')
--------------------------------
perrito4\oracle
 
PLATFORM_SLASH (new 12.1)
Returns the forward or back-slash for the operating system environment SYSCONTEXT('USERENV', 'PLATFORM_SLASH')
SELECT sys_context('USERENV', 'PLATFORM_SLASH')
FROM dual;

SYS_CONTEXT('USERENV','PLATFORM_SLASH')
---------------------------------------
/
 
POLICY_INVOKER
The invoker of row-level security (RLS) policy functions SYS_CONTEXT('USERENV', 'POLICY_INVOKER')
SELECT sys_context('USERENV', 'POLICY_INVOKER') FROM dual;
 
PROXY_ENTERPRISE_IDENTITY
Returns the Oracle Internet Directory DN when the proxy user is an enterprise user SYS_CONTEXT('USERENV', 'PROXY_ENTERPRISE_IDENTITY')
TBD
 
PROXY_USER
Name of the database user who opened the current session on behalf of the SESSION_USER SYS_CONTEXT('USERENV', 'PROXY_USER')
conn dam42z[m12345]@oratest

SELECT sys_context('USERENV', 'PROXY_USER') FROM dual;

SYS_CONTEXT('USERENV', 'PROXY_USER')
------------------------------------------------
DM42Z
 
PROXY_USERID
Identifier of the database user who opened the current session on behalf of SESSION_USER SYS_CONTEXT('USERENV', 'PROXY_USERID')
conn dam42z[m12345]@oratest

SELECT sys_context('USERENV', 'PROXY_USER') FROM dual;

SYS_CONTEXT('USERENV', 'PROXY_USERID')
------------------------------------------------
247
 
SCHEDULER_JOB (new 12.1)
Returns Y if the current session belongs to a foreground job or background job. Otherwise, returns N. SYSCONTEXT('USERENV', 'SCHEDULER_JOB')
SELECT sys_context('USERENV', 'SCHEDULER_JOB')
FROM dual;

SYS_CONTEXT('USERENV','SCHEDULER_JOB')
--------------------------------------
N
 
SERVER_HOST
The host name of the machine on which the instance is running SYS_CONTEXT('USERENV', 'SESSION_USER')
SELECT sys_context('USERENV', 'SERVER_HOST') FROM dual;

SYS_CONTEXT('USERENV','SERVER_HOST')
------------------------------------
perrito4
 
SERVICE_NAME
The name of the service to which a given session is connected SYS_CONTEXT('USERENV', 'SERVICE_NAME')
-- connect to the CDB
SQL> conn sys@orabeta as sysdba
Enter password: *********
Connected.

SQL> SELECT sys_context('USERENV', 'SERVICE_NAME') FROM dual;

SYS_CONTEXT('USERENV','SERVICE_NAME')
-------------------------------------------------------------
orabeta

-- connect to a PDB
SQL> conn uwclass/uwclass@orabase
Connected.

SQL> SELECT sys_context('USERENV', 'SERVICE_NAME') FROM dual;

SYS_CONTEXT('USERENV','SERVICE_NAME')
-------------------------------------------------------------
orabase
 
SESSION_EDITION_ID
The id number of the current edition in the session SYS_CONTEXT('USERENV', 'SESSION_EDITION_ID')
SELECT sys_context('USERENV', 'SESSION_EDITION_ID') FROM dual;

SYS_CONTEXT('USERENV','SESSION_EDITION_ID')
-------------------------------------------
131
 
SESSION_EDITION_NAME
The name of the current edition in the session SYS_CONTEXT('USERENV', 'SESSION_EDITION_NAME')
SELECT sys_context('USERENV', 'SESSION_EDITION_NAME') FROM dual;

SYS_CONTEXT('USERENV', 'ESSION_EDITION_NAME')
---------------------------------------------
ORA$BASE
 
SESSION_USER
Database user name by which the current user is authenticated. Remains the same for the duration of the session. SYS_CONTEXT('USERENV', 'SESSION_USER')
SELECT sys_context('USERENV', 'SESSION_USER') FROM dual;

SYS_CONTEXT('USERENV','SESSION_USER')
-------------------------------------
UWCLASS
 
SESSION_USERID
Identifier of the database user name by which the current user is authenticated SYS_CONTEXT('USERENV', 'SESSION_USERID')
SELECT sys_context('USERENV', 'SESSION_USERID') FROM dual;

SYS_CONTEXT('USERENV','SESSION_USERID')
---------------------------------------
102
 
SESSIONID
The auditing session identifier. Cannot be used with distributed SQL statements: Equivalent to the AUDSID column in gv$session. SYS_CONTEXT('USERENV', 'SESSIONID')
SELECT sys_context('USERENV', 'SESSIONID') FROM dual;

SYS_CONTEXT('USERENV','SESSIONID')
----------------------------------
60074
 
SID
The session number (different from the session ID) SYS_CONTEXT('USERENV', 'SID')
SELECT sys_context('USERENV', 'SID') FROM dual;

SYS_CONTEXT('USERENV','SID')
----------------------------
10
 
STATEMENTID
The auditing statement identifier SYS_CONTEXT('USERENV', 'STATEMENTID')
TBD
 
SYS_SESSION_ROLES
This is a twist on the SYS_CONTEXT function as it does not use USERENV. With this usage SYS_CONTEXT queries the list of the user's current default roles and returns TRUE if the role is granted. SYS_CONTEXT('SYS_SESSION_ROLES', 'SUPERVISOR')
conn scott/tiger@pdborcl

SELECT sys_context('SYS_SESSION_ROLES', 'RESOURCE')
FROM dual;

SYS_CONTEXT('SYS_SESSION_ROLES','SUPERVISOR')
---------------------------------------------
FALSE

conn sys@pdborcl as sysdba

GRANT resource TO scott;

conn scott/tiger@pdborcl

SELECT sys_context('SYS_SESSION_ROLES', 'RESOURCE')
FROM dual;

SYS_CONTEXT('SYS_SESSION_ROLES','SUPERVISOR')
---------------------------------------------
TRUE
 
TERMINAL
The operating system identifier for the client of the current session SYS_CONTEXT('USERENV', 'TERMINAL')
SELECT sys_context('USERENV', 'TERMINAL') FROM dual;

SYS_CONTEXT('USERENV','TERMINAL')
---------------------------------
PERRITO4
 
Context Demo
User Created Contexts CREATE OR REPLACE CONTEXT App_Ctx using My_pkg
ACCESSED GLOBALLY;

CREATE OR REPLACE PACKAGE my_pkg AUTHID DEFINER IS
 PROCEDURE set_session_id(p_session_id NUMBER);
 PROCEDURE set_ctx(p_name VARCHAR2, p_value VARCHAR2);
 PROCEDURE close_session(p_session_id NUMBER);
END my_pkg;
/

CREATE OR REPLACE PACKAGE BODY my_pkg IS
 g_session_id NUMBER;
 PROCEDURE set_session_id(p_session_id NUMBER) IS
BEGIN
  g_session_id := p_session_id;
  dbms_session.set_identifier(p_session_id);
END set_session_id;
--===============================================
PROCEDURE set_ctx(p_name VARCHAR2, p_value VARCHAR2) IS
BEGIN
  dbms_session.set_context('App_Ctx',p_name,p_value,USER,g_session_id);
END set_ctx;
--===============================================
PROCEDURE close_session(p_session_id NUMBER) IS
BEGIN
  dbms_session.set_identifier(p_session_id);
  dbms_session.clear_identifier;
END close_session;
--===============================================
END my_pkg;
/

col var1 format a10
col var2 format a10

exec my_pkg.set_session_id(1234);
exec my_pkg.set_ctx('Var1', 'Val1');
exec my_pkg.set_ctx('Var2', 'Val2');

SELECT sys_context('app_ctx', 'var1') var1, sys_context('app_ctx', 'var2') var2
FROM dual;

-- log out and back in ... at first, the context is empty-but once the session is rejoin it appears

disconnect
connect uwclass/uwclass

SELECT sys_context('app_ctx', 'var1') var1, sys_context('app_ctx', 'var2') var2
FROM dual;

exec my_pkg.set_session_id(1234);

SELECT sys_context('app_ctx', 'var1') var1, sys_context('app_ctx', 'var2') var2
FROM dual;

-- this context is tied to the specified user above, if NULL was used anyone can join this session).

grant execute on my_pkg to scott;

conn scott/tiger

exec uwclass.my_pkg.set_session_id(1234);

SELECT sys_context('app_ctx', 'var1') var1, sys_context('app_ctx', 'var2') var2
FROM dual;

-- return to the set context again and clear it
conn uwclass/uwclass

exec my_pkg.set_session_id(1234);

SELECT sys_context('app_ctx', 'var1') var1, sys_context('app_ctx', 'var2') var2
FROM dual;

exec my_pkg.close_session(1234);

SELECT sys_context('app_ctx', 'var1') var1, sys_context('app_ctx', 'var2') var2
FROM dual;
Another Demo CREATE TABLE all_objs AS
SELECT object_name
FROM dba_objects_ae;

CREATE VIEW all_objs_view AS
SELECT COUNT(*) obj_count
FROM all_objs
WHERE object_name = sys_context('UW_NAMESPACE', 'UW_PARAMETER');

CREATE OR REPLACE PROCEDURE set_param(valin IN VARCHAR2) AUTHID CURRENT_USER IS
BEGIN
  dbms_session.set_context('UW_NAMESPACE', 'UW_PARAMETER', valin);
END;
/

CREATE CONTEXT uw_namespace USING set_param;

exec SET_PARAM(valin => 'DBMS_SQL');

SELECT * FROM all_objs_view;

exec set_param(valin => 'ZZZ');

SELECT * FROM all_objs_view;
 
SYS_CLUSTER_PROPERTIES
CLUSTER_STATE
Determine whether a cluster is in rolling patch mode SYS_CONTEXT('SYS_CLUSTER_PROPERTIES', 'CLUSTER_STATE')
SELECT sys_context('SYS_CLUSTER_PROPERTIES', 'CLUSTER_STATE')
FROM DUAL;
 
Determine a cluster's patch level SYS_CONTEXT('SYS_CLUSTER_PROPERTIES', 'CURRENT_PATCHLVL')
SELECT sys_context('SYS_CLUSTER_PROPERTIES', 'CURRENT_PATCHLVL')
FROM DUAL;

Related Topics
Context
DBMS_APPLICATION_INFO
DBMS_SESSION
DBMS_SESSION
DBMS_STANDARD
DDL Event Triggers
Functions
Real Application Clusters
Row Level Security
System Event Triggers
USERENV