1

Here's a user context, and a package that sets a value in it.

create or replace context t1_ctx using t1_pkg accessed globally;

create or replace package t1_pkg
as
    procedure setx;
end t1_pkg;

create or replace package body t1_pkg
as
    procedure setx is
    begin
        dbms_session.set_context('t1_ctx','x','1');    
    end;
end t1_pkg;

But, it seems that I can't get the context variable set. Both before and after the call to setx, 'x' remains NULL.

mh> select sys_context('t1_ctx', 'x') from dual;
sys_context('t1_ctx','x') 
------------------------- 
NULL                      

mh> exec t1_pkg.setx;

mh> select sys_context('t1_ctx', 'x') from dual;
sys_context('t1_ctx','x') 
------------------------- 
NULL                      <---- I expect this should be '1' ???

How do I set a variable in my user context?

1

The above works just fine.

SQL> create or replace context t1_ctx using t1_pkg accessed globally;

Context created.

SQL>

create or replace package t1_pkg
as
    procedure setx;
end t1_pkg;
/

Package created.

SQL>

create or replace package body t1_pkg
as
    procedure setx is
    begin
        dbms_session.set_context('t1_ctx','x','1');
    end;
end t1_pkg;
/

Package body created.

SQL> select sys_context('t1_ctx', 'x') from dual;

SYS_CONTEXT('T1_CTX','X')
--------------------------------------------------------------------------------


SQL> exec t1_pkg.setx;

PL/SQL procedure successfully completed.

SQL> select sys_context('t1_ctx', 'x') from dual;

SYS_CONTEXT('T1_CTX','X')
--------------------------------------------------------------------------------
1
  • Looks like this value is persisted across sessions. Is there a way to hold a different value for each session / connection? – Guest Aug 22 '18 at 20:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.