World Library  
Flag as Inappropriate
Email this Article

Oracle metadata

Article Id: WHEBN0003015059
Reproduction Date:

Title: Oracle metadata  
Author: World Heritage Encyclopedia
Language: English
Subject: Oracle Database, Oracle Enterprise Metadata Manager, Metadata
Collection:
Publisher: World Heritage Encyclopedia
Publication
Date:
 

Oracle metadata

The Oracle Database contains tables which describe what database objects – i.e. tables, procedures, triggers etc. – exist within the database. This information about the information is known as metadata.

Oracle metadata is information contained within the Oracle Database about the objects contained within the Oracle database. You can use this information to find all tables accessible by a user, get a list of stored procedures, and get information about many other types of objects in an Oracle database.

The ORACLE application server and Oracle relational database keep metadata in two areas: data dictionary tables (accessed via built-in views) and a metadata registry.

Views for metadata

The total number of these views depends on the Oracle version, but is in a 1000 range.

The main built-in views accessing Oracle RDBMS data dictionary tables are few, and are as follows:

  • ALL_TABLES – list of all tables in the current database that are accessible to the current user
  • ALL_VIEWS – list of all views in the current database that are accessible to the current user
  • ALL_TAB_COLUMNS – list of all columns in the database that are accessible to the current user
  • ALL_ARGUMENTS – lists the arguments of functions and procedures that are accessible to the current user
  • ALL_ERRORS – lists descriptions of errors on all stored objects (views, procedures, functions, packages, and package bodies) that are accessible to the current user
  • ALL_OBJECT_SIZE – included for backward compatibility with Oracle version 5
  • ALL_PROCEDURES – (from Oracle 9 onwards) lists all functions and procedures (along with associated properties) that are accessible to the current user
  • ALL_SOURCE – describes the text (i.e. PL/SQL) source of the stored objects accessible to the current user

In addition there are equivalent views prefixed "USER_" which show only the objects owned by the current user (i.e. a more restricted view of metadata) and prefixed "DBA_" which show all objects in the database (i.e. an unrestricted global view of metadata for the database instance). Naturally the access to "DBA_" metadata views requires specific privileges.

Example 1: finding tables

Find all Tables that have PATTERN in the table name

   SELECT
      TABLE_NAME
   FROM
      ALL_TABLES
   WHERE
      TABLE_NAME LIKE '%PATTERN_TO_FIND%'
   ORDER
      BY TABLE_NAME;

Example 2: finding columns

Find all tables that have at least one column that matches a specific PATTERN in the column name

   SELECT
      TABLE_NAME,
      COLUMN_NAME
   FROM
      ALL_TAB_COLUMNS
   WHERE
      COLUMN_NAME LIKE '%PATTERN%';

Example 3: counting rows of columns

Estimate a total number of rows in all tables containing a column name that matches PATTERN (this is SQL*Plus specific script)

   COLUMN DUMMY NOPRINT
   COMPUTE SUM OF NUM_ROWS ON DUMMY
   BREAK ON DUMMY
   SELECT
      NULL DUMMY,
      T.TABLE_NAME,
      C.COLUMN_NAME,
      T.NUM_ROWS
   FROM
      ALL_TABLES T,
      ALL_TAB_COLUMNS C
   WHERE
      T.TABLE_NAME = C.TABLE_NAME
      AND C.COLUMN_NAME LIKE '%PATTERN%'
      AND T.OWNER = C.OWNER
   ORDER BY T.TABLE_NAME;

Note that NUM_ROWS records the number of rows which were in a table when (and if) it was last analyzed. This will most likely deviate from the actual number of rows currently in the table.

Example 4: finding view columns

Find view columns

SELECT TABLE_NAME,
       column_name,
       decode(c.DATA_TYPE,
              'VARCHAR2',
              c.DATA_TYPE || '(' || c.DATA_LENGTH || ')',
              'NUMBER',
              DECODE(c.data_precision, 
                     NULL, 
                     c.DATA_TYPE, 
                     0, 
                               c.DATA_TYPE, 
                     c.DATA_TYPE || '(' || c.data_precision || DECODE(c.data_scale, 
                                                                      NULL, 
                                                                      ')', 
                                                                      0, 
                                                                      ')' , 
                                                                      ', ' || c.data_scale || ')')),
              c.DATA_TYPE) data_type
  FROM cols c, obj o
  WHERE c.TABLE_NAME = o.object_name
     AND o.object_type = 'VIEW'     
     AND c.table_name LIKE '%PATTERN%'
     ORDER BY c.table_name, c.column_id;

Warning: This is incomplete with respect to multiple datatypes including char, varchar and timestamp and uses extremely old, deprecated dictionary views, back to oracle 5.

Use of underscore in table and column names

The underscore is a special SQL pattern match to a single character and should be escaped if you are in fact looking for an underscore character in the LIKE clause of a query.

Just add the following after a LIKE statement:

  ESCAPE '_'

And then each literal underscore should be a double underscore: __

Example

  LIKE '%__G' ESCAPE '_'

Oracle Metadata Registry

The Oracle product Oracle Enterprise Metadata Manager (EMM) is an ISO/IEC 11179 compatible metadata registry. It stores administered metadata in a consistent format that can be used for metadata publishing. In January 2006, EMM was available only through Oracle consulting services.

See also

External links

  • article on Oracle Metadata
This article was sourced from Creative Commons Attribution-ShareAlike License; additional terms may apply. World Heritage Encyclopedia content is assembled from numerous content providers, Open Access Publishing, and in compliance with The Fair Access to Science and Technology Research Act (FASTR), Wikimedia Foundation, Inc., Public Library of Science, The Encyclopedia of Life, Open Book Publishers (OBP), PubMed, U.S. National Library of Medicine, National Center for Biotechnology Information, U.S. National Library of Medicine, National Institutes of Health (NIH), U.S. Department of Health & Human Services, and USA.gov, which sources content from all federal, state, local, tribal, and territorial government publication portals (.gov, .mil, .edu). Funding for USA.gov and content contributors is made possible from the U.S. Congress, E-Government Act of 2002.
 
Crowd sourced content that is contributed to World Heritage Encyclopedia is peer reviewed and edited by our editorial staff to ensure quality scholarly research articles.
 
By using this site, you agree to the Terms of Use and Privacy Policy. World Heritage Encyclopedia™ is a registered trademark of the World Public Library Association, a non-profit organization.
 


Copyright © World Library Foundation. All rights reserved. eBooks from Project Gutenberg are sponsored by the World Library Foundation,
a 501c(4) Member's Support Non-Profit Organization, and is NOT affiliated with any governmental agency or department.