Oracle uses the term "Data Dictionary" for its system catalogs. Each Oracle database has its
own set of system tables and views that store information about both the physical and logical
database structure. The data dictionary objects are read-only, meaning that no database
user ever manually modifies them; however, Oracle RDBMS itself automatically updates
data in these objects in response to specific actions. For example, when user ACME creates
a new object (table, view, stored procedure, etc.), adds a column or a constraint to a table,
and so forth, the appropriate data dictionary tables are updated behind the scenes at once,
and the corresponding changes are visible through the system views (discussed later in this
chapter).
Oracle's data dictionary consists of hundreds of different views and tables that logically
belong to different categories, but most of them are only of interest to the database
administrators and are beyond the scope of this book. We list only the main object groups in
the information schema and briefly describe the most common objects in each category.
The base tables contain all database information that is dynamically updated by Oracle
RDBMS. Oracle strictly discourages using those tables even for selects; the database users
normally have no access to them, and even DBAs do not typically query these tables
directly. The information stored in the base tables is cryptic and difficult to understand.
The user-accessible views summarize and display the information stored in the base tables;
they display the information from the base tables in readable and/or simplified form using
joins, column aliases, and so on. Different Oracle users can have SELECT privileges on
different database views.
Note
All Oracle data dictionary objects belong to a special user called SYS. Oracle
creates public synonyms to simplify user access to these objects (see
Chapter 4). That means you do not have to, for example, refer to
SYS.DBA_TABLES with the fully qualified name; simply DBA_TABLES will do,
assuming you have appropriate privileges to access the view.
The data dictionary views, in turn, consist of static and dynamic views. The name "static"
denotes that the information in this group of views only changes when a change is made to
the data dictionary (a column is added to a table, a new database user is created, etc.). The
dynamic views are constantly updated while a database is in use; their contents relate
primarily to performance and are not relevant to this book.
Note
The dynamic data dictionary views can be distinguished by the prefix V_$,
and the public synonyms for these views start with V$.
The static views can be divided into three groups. The views in each group are prefixed
USER_, ALL_, or DBA_, as shown in Table 13-2.
Table 13-2: Static View Prefixes
Prefix Scope
USER User's view (objects in the user's schema).
Table 13-2: Static View Prefixes
Prefix Scope
ALL Expanded user's view (all objects that the user can access).
DBA Database administrator's view (all objects in all users' schemas).
The set of columns is almost identical across views, that is, USER_TABLES, ALL_TABLES,
and DBA_TABLES have the same columns, except USER_TABLES does not have column
OWNER (which is unnecessary because that view only has information about tables that
belong to the user who queries the view).
Table 13-3 contains information about the most commonly used static views.
Table 13-3: Selected Oracle Data Dictionary views
The select privilege for USER_ and ALL_ views (as well as for selected V$ views) is granted
to PUBLIC by default; DBA_ views are visible to privileged users only.
COLUMNS USER_TAB_COLUMNS
COLUMN_PRIVILEGES USER_COL_PRIVS
CONSTRAINT_COLUMN_USAGE USER_CONS_COLUMNS
CONSTRAINT_TABLE_USAGE USER_CONSTRAINTS
KEY_COLUMN_USAGE USER_CONS_COLUMNS
REFERENTIAL_CONSTRAINTS USER_CONSTRAINTS
TABLES USER_TABLES
USER_OBJECTS
TABLE_CONSTRAINTS USER_CONSTRAINTS
TABLE_PRIVILEGES USER_COL_PRIVS
USAGE_PRIVILEGES USER_COL_PRIVS
VIEWS USER_VIEWS
USER_OBJECTS
VIEW_COLUMN_USAGE USER_TAB_COLUMNS
The following query (when issued by user ACME in the ACME sample database) retrieves the
names and creation dates of all tables that belong to the current user:
SELECT object_name, created
FROM user_objects WHERE object_type = 'TABLE';
OBJECT_NAME CREATED
------------------------------------------------
--------- ADDRESS 27-OCT-02
CUSTOMER 27-OCT-02 DISCOUNT 27-OCT-02 ORDER_HEADER
27-OCT-02 ORDER_LINE
27-OCT-02 ORDER_SHIPMENT 27-OCT-02 PAYMENT_TERMS 27-
OCT-02 PHONE 27-OCT-02
PRODUCT 27-OCT-02 RESELLER 27-OCT-02 SALESMAN 27-
OCT-02 SHIPMENT 27-OCT-02
STATUS 27-OCT-02 13 rows selected.
The query results tell us that there are currently 13 tables in the ACME database that belong
to user ACME and that all of them were created on October 27, 2002.
The system catalog views can be joined just as any other views or tables in Oracle to
produce some combined output. The query below joins USER_TABLES and
USER_TAB_COLS data dictionary views to produce the list of all columns in ADDRESS table
that belongs to user ACME:
SELECT
table_name, column_name FROM user_tables JOIN
user_tab_cols USING (table_name)
WHERE table_name = 'ADDRESS'; TABLE_NAME COLUMN_NAME
------------------------------
------------------------------ ADDRESS ADDR_ID_N
ADDRESS ADDR_CUSTID_FN ADDRESS ADDR_SALESMANID_FN
ADDRESS ADDR_ADDRESS_S
ADDRESS ADDR_TYPE_S ADDRESS ADDR_CITY_S ADDRESS
ADDR_STATE_S ADDRESS ADDR_ZIP_S
ADDRESS ADDR_COUNTRY_S 9 rows selected.
You can use a simple SQL query to look for objects that contain the information you need.
For example, if you want to know which columns in which tables you have permission to
modify, a query similar to one below can help you to find out:
SELECT *
FROM dictionary WHERE UPPER(comments) LIKE
'%UPDAT%'; TABLE_NAME COMMENTS
------------------------
-----------------------------------
ALL_UPDATABLE_COLUMNS Description of all updatable
columns
USER_UPDATABLE_COLUMNS Description of updatable
columns
The other view, DICT_COLUMNS, gives you information about the individual columns of the
data dictionary objects. The query below displays all the columns in the USER_OBJECTS
view along with comments for these columns:
SELECT *
from dict_columns WHERE table_name = 'USER_OBJECTS';
TABLE_NAME COLUMN_NAME
COMMENTS ---------------- ---------------
----------------------------
USER_OBJECTS OBJECT_NAME Name of the object
USER_OBJECTS SUBOBJECT_NAME Name of
the sub-object (for example, partition) USER_OBJECTS
OBJECT_ID Object number of
the object USER_OBJECTS DATA_OBJECT_ID Object number
of the segment which
contains the object USER_OBJECTS OBJECT_TYPE Type of
the object USER_OBJECTS
CREATED Timestamp for the creation of the object
USER_OBJECTS LAST_DDL_TIME
Timestamp for the last DDL change (including GRANT
and REVOKE) to the object
USER_OBJECTS TIMESTAMP Timestamp for the
specification of the object
USER_OBJECTS STATUS Status of the object
USER_OBJECTS TEMPORARY Can the current
session only see data that it place in this object
itself? USER_OBJECTS
GENERATED Was the name of this object system
generated? USER_OBJECTS SECONDARY
Is this a secondary object created as part of
icreate for domain indexes? 12
rows selected.
Tip
You can use the DESCRIBE command to obtain some minimal information
about the data dictionary views and tables in exactly the same way that you
would use it to inquire about any other database objects, for example:
DESCRIBE user_sequences Name
Null? Type ---------------- --------
------------- SEQUENCE_NAME NOT NULL
VARCHAR2(30) MIN_VALUE NUMBER
MAX_VALUE NUMBER
INCREMENT_BY NOT NULL NUMBER
CYCLE_FLAG VARCHAR2(1) ORDER_FLAG VARCHAR2(1)
CACHE_SIZE NOT NULL NUMBER
LAST_NUMBER NOT NULL NUMBER
Bien plus que des documents.
Découvrez tout ce que Scribd a à offrir, dont les livres et les livres audio des principaux éditeurs.
Annulez à tout moment.