Modify Custom End-User Context Attributes

After a custom context is defined and instantiated in an end-user security context, you can update individual attribute values using a standard UPDATE statement on the SYS.END_USER_CONTEXT view. This allows application code or PL/SQL handlers to set dynamic attribute values during a session.

Note: Updating a context attribute implicitly instantiates the custom context if it has not already been instantiated. This implicit instantiation requires the SELECT privilege on the context, in addition to the UPDATE privilege required to modify the attribute. Therefore, when updating an end-user context for the first time, you must have both SELECT and UPDATE privileges.

Required privilege

Syntax

UPDATE SYS.END_USER_CONTEXT t
SET    t.CONTEXT.attribute = value
WHERE  OWNER = owner AND NAME = name;

Parameters

Parameter Description
owner The schema name (owner) of the custom context to update.
name The name of the custom context to update.
attribute The attribute within the custom context whose value is being changed.
value The new value to assign to the attribute. Must conform to the attribute’s declared data type.

Usage notes and restrictions

For syntax diagrams and additional details, see UPDATE END USER CONTEXT in Oracle AI Database SQL Language Reference.

Example: Set an end-user context attribute for the current security context

Set the emp_id attribute in hr.hcm_context to 3 for the current end-user security context.

UPDATE SYS.END_USER_CONTEXT t
SET    t.CONTEXT.emp_id = 3
WHERE  owner = 'HR' AND name = 'HCM_CONTEXT';

Example: Implement a PL/SQL callback to populate an attribute value at runtime

If a PL/SQL callback is specified, create and implement the packages and procedures as needed to populate the attribute value at runtime.

CREATE OR REPLACE PACKAGE BODY hr.hcm_core AS
  PROCEDURE init_user_context IS
   sql_stmt VARCHAR2(1000);
  BEGIN
   -- application logic...
   sql_stmt := 'UPDATE END_USER_CONTEXT t SET t.CONTEXT.emp_id = 100 WHERE owner = ''HR'' and name = ''HCM_CONTEXT''';
   EXECUTE IMMEDIATE sql_stmt;
  END;
END;
/