The SET_CONTEXT procedure sets the context, which includes four types: session-local, global initialization, external initialization, and global access.
Applicability
This topic applies only to OceanBase Database Enterprise Edition. OceanBase Database Community Edition does not support this feature.
Syntax
DBMS_SESSION.SET_CONTEXT (
namespace VARCHAR2,
attribute VARCHAR2,
value VARCHAR2,
username VARCHAR2,
client_id VARCHAR2 );
Parameters
| Parameter | Description |
|---|---|
| namespace | The namespace of the application context to be set. The maximum length is 128 bytes. |
| attribute | The attribute of the application context to be set. The maximum length is 128 bytes. |
| value | The value of the application context to be set. The maximum length is 4 KB. |
| username | The database username attribute of the application context. The default value is NULL. |
| client_id | The client_id attribute of the application in the application context. The maximum length is 64 bytes. The default value is NULL. |
Note
Among the five parameters of the SET_CONTEXT procedure, only the first three are required. The last two are optional and are used only in global access contexts.
Considerations
The
usernameparameter must be a valid SQL identifier.The
client_idparameter must be a string of up to 64 bytes. It is case-sensitive and must match the value provided by theset_identifierparameter.If the
namespaceparameter specifies a global context namespace, theusernameparameter must match the current database username in the session, and theclient_idparameter must match the currentclient_idin the session. If these parameters are not set, they are consideredNULL, allowing any user to view the context value.The
SET_CONTEXTprocedure must be called directly or indirectly by a trusted package.If a parameter value is already set in the namespace,
SET_CONTEXTwill overwrite the existing value.Changes to context values made by the
SET_CONTEXTprocedure take effect immediately. Subsequent calls toSYS_CONTEXTwill return the updated value.
Examples
CREATE PROCEDURE emp_attr(empname IN VARCHAR2, empno IN NUMBER) IS
BEGIN
DBMS_SESSION.SET_CONTEXT('emp_context',empname, empno);
END;
