Use USER_ views to get information on database objects
Oracle provides several views that allow you to extract
information on database objects (tables, views, procedures
etc). Three important ones are
USER_OBJECTS, USER_SOURCE and USER_DEPENDENCIES. These
views contain information on database objects owned by
the currently logged in user (schema).
1) USER_OBJECTS: Querying this view yields information
about object names, types, status (valid or invalid)
and (most usefully in my experience), the last time the
object was compiled or modified. Here's an example query
on this view:
select
object_name, object_type, status, last_ddl_time
from
user_objects
order by
4
This query gives the name, type, status and the last modification
date of all objects owned by the current user. This can be useful
when, for instance, you want to know the last time a procedure was
recompiled. There are several other columns in this view - see the
Oracle docs for details.
2) USER_SOURCE: This view is useful when you want to search your
compiled code (procedures and functions) for a particular keyword.
The column TEXT contains the first two thousand characters of all
procedures and functions. Here's an example query that returns
all procedure and function names that contain the string 'EMPLOYEE'.
select
distinct name, type
from
user_source
where
upper(text) like '%EMPLOYEE%'
The source for triggers and views are contained in the views USER_TRIGGERS
and USER_VIEWS respectively. The column TRIGGER_BODY contains the trigger
text in the former and the column TEXT contains the view text in the
latter. These columns cannot be searched because they are of
type LONG, not VARCHAR!
3) USER_DEPENDENCIES: This view is invaluable when you need to find
out which objects depend on a particular object. For instance, you may
want to know which objects may be invalidated when you recompile a
procedure called CALCULATE_REPORTS. Here's the query:
select
referenced_name, referenced_type
from
user_dependencies
where
name='CALCULATE_REPORTS'
The query will return a list of all database objects referenced by the
object CALCULATE_REPORTS. USER_DEPENDENCIES contains other columns of
interest- check the docs for details.
Notes:
1) USER_ views return information pertaining to objects owned by the
current schema. Two other families of views exist: ALL_ and DBA_.
Generally, for each USER_ view, there are corresponding ALL_ and DBA
views (eg: ALL_OBJECTS, DBA_OBJECTS). The
ALL_ views give information on all objects to which the current user has
access (i.e. objects owned by the user+objects to which the user has
been granted access), and the DBA_ views give information on database
objects across all schemas. DBA_ views can contain more columns
than the corresponding ALL_ or USER_ views.
2) There are several other USER_ views than those dealt with here, and
it is useful to know about these when you want to investigate database
issues. Check the Oracle docs for details. The pertinent book is
the Oracle 8i (or 9i) Reference.