The SET_CONTEXT procedure sets a context in any of the following types: session local, globally initialized, external initialized, and globally accessed.
Applicability
This topic applies only to OceanBase Database Enterprise Edition. OceanBase Database Community Edition provides only the MySQL mode.
Syntax
DBMS_SESSION.SET_CONTEXT (
namespace VARCHAR2,
attribute VARCHAR2,
value VARCHAR2,
username VARCHAR2,
client_id VARCHAR2 );
Parameters
| Parameter | Description |
|---|---|
| namespace | The name of the namespace to which the application context to be set belongs. The maximum value length allowed is 128 bytes. |
| attribute | The attribute of the application context to be set. The maximum value length allowed is 128 bytes. |
| value | The value of the application context to be set. The maximum value length allowed is 4 KB. |
| username | The database username of the application context to be set. Default value: NULL. |
| client_id | The client ID of the application whose context is to be set. The maximum value length allowed is 64 bytes. Default value: NULL. |
Description
In the five parameters of the SET_CONTEXT procedure, the former three are required, and the latter two are optional and used only in a globally accessed context.
Considerations
The value of the
usernameparameter must a valid SQL identifier.The value of the
client_idparameter must be a string of a maximum of 64 bytes. It is case sensitive and must match the parameter provided by theSET_IDENTIFIERprocedure.If the value of the
namespaceparameter is a global context namespace, the value of theusernameparameter matches the current database name in the session, and the value of theclient_idparameter matches the currentclient IDvalue in the session. If these parameters are not set, the valueNULLtakes effect for them. In this case, any user can view the context value.The
SET_CONTEXTprocedure must be directly or indirectly called by a trusted package.If a parameter value has been set in the namespace, the
SET_CONTEXTprocedure will override this value.Any change made by using the
SET_CONTEXTprocedure to the context value takes effect immediately and subsequent calls to access the value by using theSYS_CONTEXTfunction return the latest value.
Examples
CREATE PROCEDURE emp_attr(empname IN VARCHAR2, empno IN NUMBER) IS
BEGIN
DBMS_SESSION.SET_CONTEXT('emp_context',empname, empno);
END;