关于用户定义的上下文要记住的一件事是它们可以被保护,以便它们只能被某个PL / SQL包修改。
举个例子:
CREATE OR REPLACE PACKAGE my_context_pkg AS PROCEDURE set_context_a ( p_value VARCHAR2 ); END; CREATE OR REPLACE PACKAGE BODY my_context_pkg AS PROCEDURE set_context_a ( p_value VARCHAR2 ) IS BEGIN DBMS_SESSION.SET_CONTEXT('MY_CONTEXT','A',p_value); END; END; -- Tell Oracle that only my_context_pkg can modify context CREATE CONTEXT my_context USING my_context_pkg; -- This will fail EXEC DBMS_SESSION.SET_CONTEXT('MY_CONTEXT','A','5'); -- This will succeed EXEC my_context_pkg.set_context_a ('5');