CREATE END USER CONTEXT

Purpose

Use CREATE END USER CONTEXT to define a new, custom end-user context object in the database. The context definition specifies a set of named attributes, their data types, default values, and optional PL/SQL event handlers. The definition acts as a template that the database instantiates at runtime within each end-user security context. You can assign each attribute a default value or associate it with a PL/SQL handler function for lazy loading on first read.

Prerequisites

You must have the CREATE END USER CONTEXT system privilege in order to create an end-user context in your own schema.

You must have the CREATE ANY END USER CONTEXT system privilege in order to create an end-user context in a schema other than your own.

Syntax

Description of the illustration create_end_user_context.gif

json_schema::=

Description of the illustration json_schema.gif

context_properties::=

Description of the illustration context_properties.gif

attribute::=

Description of the illustration attribute.gif

regular_attribute::=

Description of the illustration regular_attribute.gif

attr_details::=

Description of the illustration attr_details.gif

attr_type::=

Description of the illustration attr_type.gif

property_name_value::=

Description of the illustration property_name_value.gif

nested_attribute::=

Description of the illustration nested_attribute.gif

Semantics

Example

The following SQL statement creates an end user context object called hcm in hr schema:

CREATE END USER CONTEXT hr.hcm USING JSON SCHEMA '{
  "type": "object",
  "properties": {
    "emp_id": {
      "type": "integer",
      "o:onFirstRead": "hr.hcm_core.init_user_context"
    },
    "service_center_id": {
      "type": "integer",
      "default": 1
    }
  }
}';

This namespace contains two attributes, emp_id and service_center_id. service_center_id default value is 1. The value of emp_id is not set at this time. When the attribute is read for the first time, the handler function hr.hcm_core.init_user_context will be invoked which should set the value for this attribute.

Note that one context can have at most one unique handler PL/SQL function specified. If the context has multiple attributes associated with PL/SQL handler function, they must reference the same schema.package.function, otherwise an error will be thrown for invalid input.