HOME

TheInfoList



OR:

Oracle Database Oracle Database (commonly referred to as Oracle DBMS, Oracle Autonomous Database, or simply as Oracle) is a multi-model database management system produced and marketed by Oracle Corporation. It is a database commonly used for running online ...
provides information about all of the tables, views,
column A column or pillar in architecture and structural engineering is a structural element that transmits, through compression (physical), compression, the weight of the structure above to other structural elements below. In other words, a column i ...
s, and procedures in a database. This information about information is known as
metadata Metadata is "data that provides information about other data", but not the content of the data, such as the text of a message or the image itself. There are many distinct types of metadata, including: * Descriptive metadata – the descriptive ...
. It is stored in two locations: data dictionary tables (accessed via built-in views) and a metadata registry. Other
relational database management system A relational database is a (most commonly digital) database based on the relational model of data, as proposed by E. F. Codd in 1970. A system used to maintain relational databases is a relational database management system (RDBMS). Many relati ...
s support an
ANSI The American National Standards Institute (ANSI ) is a private non-profit organization that oversees the development of voluntary consensus standards for products, services, processes, systems, and personnel in the United States. The organi ...
-standard equivalent called information schema.


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 A relational database is a (most commonly digital) database based on the relational model of data, as proposed by E. F. Codd in 1970. A system used to maintain relational databases is a relational database management system (RDBMS). Many relatio ...
data dictionary tables are few, and are as follows: * ALL_OBJECTS – list of all objects in the current database that are accessible to the current user; * 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; * ALL_TRIGGERS – list all the triggers 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 Owner AS Schema_Name, Table_Name FROM All_Tables WHERE Table_Name LIKE '%PATTERN%' ORDER BY Owner, 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 Owner AS Schema_Name, Table_Name, Column_Name FROM All_Tab_Columns WHERE Column_Name LIKE '%PATTERN%' ORDER BY 1,2,3;


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 The ISO/IEC 11179 Metadata Registry (MDR) standard is an international ISO/IEC standard for representing metadata for an organization in a metadata registry. It documents the standardization and registration of metadata to make data understandab ...
compatible
metadata registry A metadata registry is a central location in an organization where metadata definitions are stored and maintained in a controlled method. A metadata repository is the database where metadata is stored. The registry also adds relationships with r ...
. It stores administered metadata in a consistent format that can be used for
metadata publishing Metadata publishing is the process of making metadata data elements available to external users, both people and machines using a formal review process and a commitment to change control processes. Metadata publishing is the foundation upon which a ...
. In January 2006, EMM was available only through Oracle consulting services.


See also

* Information schema *
Metadata Metadata is "data that provides information about other data", but not the content of the data, such as the text of a message or the image itself. There are many distinct types of metadata, including: * Descriptive metadata – the descriptive ...


References

{{Reflist


External links


article on Oracle Metadata
Metadata
Metadata Metadata is "data that provides information about other data", but not the content of the data, such as the text of a message or the image itself. There are many distinct types of metadata, including: * Descriptive metadata – the descriptive ...
Articles with example SQL code