The DBMS_SESSION built-in package has been enhanced with the SET_CONTEXT procedure so that you can set the value for an attribute within a context. Here is the header for that procedure:
PROCEDURE DBMS_SESSION.SET_CONTEXT ( namespace VARCHAR2, attribute VARCHAR2, value VARCHAR2);
The parameters are listed in Table 8.2.
Parameter | Description |
|---|---|
namespace | The name of the context |
attribute | The attribute name |
value | The value to be assigned to that attribute in the current session |
This procedure can only be called inside the package specified for the namespace context in the CREATE CONTEXT statement. This relationship is shown in the following steps:
/* Filename on companion disk: earth.pkg */
CREATE CONTEXT pollution_indicators USING earth_pkg;
CREATE OR REPLACE PACKAGE earth_pkg
IS
PROCEDURE set_contexts;
END;
/
CREATE OR REPLACE PACKAGE BODY earth_pkg
IS
c_context CONSTANT VARCHAR2(30) :=
'pollution_indicators';
PROCEDURE set_contexts IS
BEGIN
DBMS_SESSION.SET_CONTEXT (
c_context, 'acidrain', 'corrosive');
DBMS_SESSION.SET_CONTEXT (
c_context, 'smog', 'dense');
END;
END;
/If you try to execute DBMS_SESSION.SET_CONTEXT "out of context," you will get an error, as shown here:
SQL> BEGIN 2 DBMS_SESSION.SET_CONTEXT ( 3 'pollution_indicators', 'smog', 'dense'); 4 END; 5 / BEGIN * ERROR at line 1: ORA-01031: insufficient privileges
![]() | ![]() | ![]() |
| 8.2 CREATE CONTEXT: Creating Contexts | ![]() | 8.4 SYS_CONTEXT and LIST_CONTEXT: Obtaining Context Information |
Copyright (c) 2000 O'Reilly & Associates. All rights reserved.
| This HTML Help has been published using the chm2web software. |