Oracle PL/SQL Programming Guide to Oracle 8i Features

Oracle PL/SQL Programming Guide to Oracle 8i FeaturesSearch this book
Previous: 8.2 CREATE CONTEXT: Creating ContextsChapter 8
Deploying Fine-Grained Access Control
Next: 8.4 SYS_CONTEXT and LIST_CONTEXT: Obtaining Context Information
 

8.3 SET_CONTEXT: Setting Context and Attribute Values

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.


Table 8.2: SET_CONTEXT Parameters

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


Previous: 8.2 CREATE CONTEXT: Creating ContextsOracle PL/SQL Programming Guide to Oracle 8i FeaturesNext: 8.4 SYS_CONTEXT and LIST_CONTEXT: Obtaining Context Information
8.2 CREATE CONTEXT: Creating ContextsBook Index8.4 SYS_CONTEXT and LIST_CONTEXT: Obtaining Context Information

The Oracle Library Navigation

Copyright (c) 2000 O'Reilly & Associates. All rights reserved.

Library Home Oracle PL/SQL Programming, 2nd. Ed. Guide to Oracle 8i Features Oracle Built-in Packages Advanced PL/SQL Programming with Packages Oracle Web Applications Oracle PL/SQL Language Pocket Reference Oracle PL/SQL Built-ins Pocket Reference