CREATE CONTEXT my_ctx USING my_pkg;
This creates a context that can only be set by routines in the database package my_pkg
, e.g.:
CREATE PACKAGE my_pkg AS
PROCEDURE set_ctx;
END my_pkg;
CREATE PACKAGE BODY my_pkg AS
PROCEDURE set_ctx IS
BEGIN
DBMS_SESSION.set_context('MY_CTX','THE KEY','Value');
DBMS_SESSION.set_context('MY_CTX','ANOTHER','Bla');
END set_ctx;
END my_pkg;
Now, if a session does this:
my_pkg.set_ctx;
It can now retrieve the value for the key thus:
SELECT SYS_CONTEXT('MY_CTX','THE KEY') FROM dual;
Value