Home » SQL & PL/SQL » SQL & PL/SQL » Namespace attributes in sys context
Namespace attributes in sys context [message #405812] Fri, 29 May 2009 11:50 Go to next message
roopla
Messages: 52
Registered: May 2006
Member
I can see the value of a attribute for a partiuclar namespace using following query
select sys_context ('USERENV','TERMINAL') FROM DUAL;
select sys_context ('USERENV','DB_NAME') FROM DUAL;

but, how to find out all attributes for a given namesapce like here 'USERENV' or any user defined namespace. Is there any query or dba view which will list all attributes for a given namespace

Thanks for your help
Re: Namespace attributes in sys context [message #405814 is a reply to message #405812] Fri, 29 May 2009 11:57 Go to previous messageGo to next message
Michel Cadot
Messages: 64098
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
USERENV predefined context is described in documentation.
Custom contexts can be seen in %CONTEXT views.

Regards
Michel
Re: Namespace attributes in sys context [message #405820 is a reply to message #405814] Fri, 29 May 2009 13:23 Go to previous messageGo to next message
roopla
Messages: 52
Registered: May 2006
Member
There is view called V$context but it is empty, there is a dba_context view, but it only lists what are all namespaces, doens't list attributes in each namespaces. Still looking for answers
Re: Namespace attributes in sys context [message #405822 is a reply to message #405820] Fri, 29 May 2009 13:31 Go to previous messageGo to next message
Michel Cadot
Messages: 64098
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
There is no attribute until you set them in your session this is why v$context is empty and this is why dba_context does not contain attributes.

Regards
Michel
Re: Namespace attributes in sys context [message #405825 is a reply to message #405812] Fri, 29 May 2009 13:42 Go to previous messageGo to next message
roopla
Messages: 52
Registered: May 2006
Member
select sys_context('TEST_CONTEXT','TEST_DATE') FROM DUAL
RETURNS TEST_DATE VALUE IN MY SESSION.
(that means attribute TEST_DATE IS ALREADY SET)

BUT, SELECT * FROM V$CONTEXT GIVES ME EMPTY

what does that mean?

Re: Namespace attributes in sys context [message #405827 is a reply to message #405820] Fri, 29 May 2009 13:52 Go to previous messageGo to next message
andrew again
Messages: 2577
Registered: March 2000
Senior Member
owa_util.print_cgi_env (for web pl/sql gateway) is similar to sys_context() and by viewing the package body, shows how it loops through an index-by table (pl/sql table) to get each name value pair.
...
   procedure print_cgi_env is
   begin
      for i in 1..owa.num_cgi_vars
      loop
         htp.print(owa.cgi_var_name(i)||' = '||owa.cgi_var_val(i)||htf.nl);
      end loop;
   end;
...

Viewing package body 'STANDARD' shows that sys_context makes an external C call and doesn't seem to expose any pl/sql structure where the name value pairs reside.

...

  function pessysctx2(namespace varchar2, attribute varchar2) return varchar2;
    pragma interface (c,pessysctx2);

  -- Special: if the ICD raises ICD_UNABLE_TO_COMPUTE, that means we should do
  -- the old 'select sys_context(...) from dual;' thing.  This allows us to do
  -- the select from PL/SQL rather than having to do it from C (within the ICD.)
  function SYS_CONTEXT(namespace varchar2, attribute varchar2)
    return varchar2 is
  c varchar2(4000);
  BEGIN
    c := pessysctx2(namespace, attribute);
    return c;
  exception
    when ICD_UNABLE_TO_COMPUTE then
      select sys_context(namespace,attribute) into c from sys.dual;
      return c;
  end;


...
Re: Namespace attributes in sys context [message #405832 is a reply to message #405825] Fri, 29 May 2009 14:58 Go to previous message
Michel Cadot
Messages: 64098
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Quote:
select sys_context('TEST_CONTEXT','TEST_DATE') FROM DUAL
RETURNS TEST_DATE VALUE IN MY SESSION.
(that means attribute TEST_DATE IS ALREADY SET)

Wrong!
Example:
SQL> create or replace package mypkg is end;
  2  /

Package created.

SQL> create context myctx using mypkg;

Context created.

SQL> select sys_context('MYCTX','INEXISTENT') from dual;
SYS_CONTEXT('MYCTX','INEXISTENT')
---------------------------------------------------------


1 row selected.

As you can see nothing exist and Oracle can answer and it answers there is no value.

More:
SQL> drop context myctx;

Context dropped.

SQL> select sys_context('MYCTX','INEXISTENT') from dual;
SYS_CONTEXT('MYCTX','INEXISTENT')
----------------------------------------------------------


1 row selected.

The context does not even exist!

Regards
Michel

[Updated on: Fri, 29 May 2009 15:01]

Report message to a moderator

Previous Topic: Procedure doent insert.
Next Topic: Tool for Test data generation and loading
Goto Forum:
  


Current Time: Fri Dec 02 12:12:01 CST 2016

Total time taken to generate the page: 0.20390 seconds