Hi Tom,
We have a similar requirement to have global values accesible across multiple
sessions.
We are currently in the process of upgrading to 9i, and was thinking of using
the global context feature to do that.
Can you provide us with a simple example to do this on 9i using global context?
Appreciate your help,
Thanks,
Followup:
ops$tkyte@ORA920> create or replace context App_Ctx using My_pkg
2 ACCESSED GLOBALLY
3 /
Context created.
ops$tkyte@ORA920>
ops$tkyte@ORA920> create or replace package my_pkg
2 as
3 procedure set_ctx( p_name in varchar2,
4 p_value in varchar2 );
5
6 procedure init;
7 end;
8 /
Package created.
ops$tkyte@ORA920>
ops$tkyte@ORA920> create or replace package body my_pkg
2 as
3 g_session_id number := 1234;
4
5 procedure init
6 is
7 begin
8 null; -- elaboration code does it all
9 end;
10
11 procedure set_ctx( p_name in varchar2,
12 p_value in varchar2 )
13 as
14 begin
15 dbms_session.set_context
16 ( 'App_Ctx', p_name, p_value, NULL, g_session_id );
17 end;
18 begin
19 dbms_session.set_identifier( g_session_id );
20 end;
21 /
Package body created.
ops$tkyte@ORA920> pause
ops$tkyte@ORA920>
ops$tkyte@ORA920> exec my_pkg.set_ctx( 'Var1', 'Val1' );
PL/SQL procedure successfully completed.
ops$tkyte@ORA920> exec my_pkg.set_ctx( 'Var2', 'Val2' );
PL/SQL procedure successfully completed.
ops$tkyte@ORA920>
ops$tkyte@ORA920> select sys_context( 'app_ctx', 'var1' ) var1,
2 sys_context( 'app_ctx', 'var2' ) var2
3 from dual
4 /
VAR1 VAR2
---------- ----------
Val1 Val2
ops$tkyte@ORA920>
ops$tkyte@ORA920> connect /
Connected.
ops$tkyte@ORA920>
ops$tkyte@ORA920> select sys_context( 'app_ctx', 'var1' ) var1,
2 sys_context( 'app_ctx', 'var2' ) var2
3 from dual
4 /
VAR1 VAR2
---------- ----------
ops$tkyte@ORA920>
ops$tkyte@ORA920> exec my_pkg.init
PL/SQL procedure successfully completed.
ops$tkyte@ORA920>
ops$tkyte@ORA920> select sys_context( 'app_ctx', 'var1' ) var1,
2 sys_context( 'app_ctx', 'var2' ) var2
3 from dual
4 /
VAR1 VAR2
---------- ----------
Val1 Val2
[@more@]
We have a similar requirement to have global values accesible across multiple
sessions.
We are currently in the process of upgrading to 9i, and was thinking of using
the global context feature to do that.
Can you provide us with a simple example to do this on 9i using global context?
Appreciate your help,
Thanks,
Followup:
ops$tkyte@ORA920> create or replace context App_Ctx using My_pkg
2 ACCESSED GLOBALLY
3 /
Context created.
ops$tkyte@ORA920>
ops$tkyte@ORA920> create or replace package my_pkg
2 as
3 procedure set_ctx( p_name in varchar2,
4 p_value in varchar2 );
5
6 procedure init;
7 end;
8 /
Package created.
ops$tkyte@ORA920>
ops$tkyte@ORA920> create or replace package body my_pkg
2 as
3 g_session_id number := 1234;
4
5 procedure init
6 is
7 begin
8 null; -- elaboration code does it all
9 end;
10
11 procedure set_ctx( p_name in varchar2,
12 p_value in varchar2 )
13 as
14 begin
15 dbms_session.set_context
16 ( 'App_Ctx', p_name, p_value, NULL, g_session_id );
17 end;
18 begin
19 dbms_session.set_identifier( g_session_id );
20 end;
21 /
Package body created.
ops$tkyte@ORA920> pause
ops$tkyte@ORA920>
ops$tkyte@ORA920> exec my_pkg.set_ctx( 'Var1', 'Val1' );
PL/SQL procedure successfully completed.
ops$tkyte@ORA920> exec my_pkg.set_ctx( 'Var2', 'Val2' );
PL/SQL procedure successfully completed.
ops$tkyte@ORA920>
ops$tkyte@ORA920> select sys_context( 'app_ctx', 'var1' ) var1,
2 sys_context( 'app_ctx', 'var2' ) var2
3 from dual
4 /
VAR1 VAR2
---------- ----------
Val1 Val2
ops$tkyte@ORA920>
ops$tkyte@ORA920> connect /
Connected.
ops$tkyte@ORA920>
ops$tkyte@ORA920> select sys_context( 'app_ctx', 'var1' ) var1,
2 sys_context( 'app_ctx', 'var2' ) var2
3 from dual
4 /
VAR1 VAR2
---------- ----------
ops$tkyte@ORA920>
ops$tkyte@ORA920> exec my_pkg.init
PL/SQL procedure successfully completed.
ops$tkyte@ORA920>
ops$tkyte@ORA920> select sys_context( 'app_ctx', 'var1' ) var1,
2 sys_context( 'app_ctx', 'var2' ) var2
3 from dual
4 /
VAR1 VAR2
---------- ----------
Val1 Val2
[@more@]
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/94317/viewspace-795160/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/94317/viewspace-795160/