Demo for Oracle Context{set_context,sys_context}
时间:2010-09-08 来源:richardliu1123
Step1>To create package and package body;
Create or replace package my_context_test as
Procedure set_value(value varchar2);
End;
Create or replace package body my_context_test as
Procedure set_value(value varchar2) as
Begin
DBMS_SESSION.SET_CONTEXT(‘test_context’,’user’,value);
End;
End;
Step2>To create context for package;
CREATE OR REPLACE CONTEXT test_context USING apps.my_context_test ACCESSED GLOBALLY
Step3>To setup context value
Declare
l_value varchar2(10);
begin
Select SYS_CONTEXT('USERENV', 'SESSION_USER') INTO l_value from dual;
my_context_test.set_value(l_value);
end;
Step4>To retire context value
Select sys_context(‘test_context’,’user’) from dual;
----------------------------------------------------------
APPS
Note:
1>You can retire dba_context for your custom context name;
2>You can retire dba_source to look at the source code of your custom package;
3>You can delete your context or package via the following grammar;
DROP CONTEXT test_contest;
DROP PACKAGE my_context_p;