Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I list all context namespaces in Oracle DB?

If I create a context namespace:-

CREATE OR REPLACE CONTEXT hr_security
    USING hr.pkg_security
    ACCESSED GLOBALLY;

How can I list all such namespaces and look up their properties. For example, hr_security can be access globally and can be set from pkg_security package.

like image 794
AppleGrew Avatar asked Nov 28 '11 11:11

AppleGrew


People also ask

What is a context namespace Oracle?

An application context is a set of name-value pairs that Oracle Database stores in memory. The application context has a label called a namespace (for example, empno_ctx for an application context that retrieves employee IDs).

What is the use of Sys_context function in Oracle?

SYS_CONTEXT returns the value of parameter associated with the context namespace . You can use this function in both SQL and PL/SQL statements. For namespace and parameter , you can specify either a string or an expression that resolves to a string designating a namespace or an attribute.

What is namespace in Dba_objects?

A namespace is the categorisation which objects are identified (and hence typically will need unique naming). eg. <code> SQL> select object_type, namespace. 2 from dba_objects.

What is userenv in Oracle?

USERENV is a legacy function that is retained for backward compatibility. Oracle recommends that you use the SYS_CONTEXT function with the built-in USERENV namespace for current functionality. See SYS_CONTEXT for more information. USERENV returns information about the current session.


2 Answers

You can query the DBA_CONTEXT (or [ALL_CONTEXT][1]) view depending on your privileges and what contexts you're looking at. ALL_CONTEXT will list all the contexts that have attributes set in the current session. DBA_CONTEXT lists all the contexts in the database. However, you need to have additional privileges to be able to query the DBA_CONTEXT view (the SELECT ANY DICTIONARY privilege or SELECT_CATALOG_ROLE role would be more than sufficient but you can also be granted access to that view specifically)

SELECT namespace,
       schema,
       package,
       type
  FROM dba_context

will have a row for the HR_SECURITY namespace showing that it is associated with the PKG_SECURITY package with a TYPE of ACCESSED GLOBALLY.

like image 84
Justin Cave Avatar answered Sep 30 '22 08:09

Justin Cave


Alternatively you can use ALL_OBJECTS if you lack grants for DBA_CONTEXT. But to list all global contexts which were created by respective user would require additional naming convention to distinguish who created this global context (as in your example owner of object will be SYS and not HR)

SELECT * FROM ALL_OBJECTS AO WHERE AO.OBJECT_TYPE = 'CONTEXT' AND AO.OBJECT_NAME LIKE 'HR%' AND AO.OWNER = 'SYS';
like image 40
Артём Томчук Avatar answered Sep 30 '22 08:09

Артём Томчук