Data Dictionary: Querying the Brain of Oracle
The Data Dictionary is the most powerful tool in Oracle. Learn how to query metadata to find missing indexes, reverse-engineer schemas, monitor active sessions, and dynamically generate SQL.
What is the Data Dictionary?
When you create a table, where does Oracle store the fact that the table exists? When you grant a privilege, where is that rule saved?
It is all stored in the Data Dictionary. The Data Dictionary is a collection of read-only tables and views owned by the SYS user. It contains the metadata (data about data) for the entire database instance.
You should never (and generally cannot) modify these tables directly via UPDATE or DELETE. Instead, you interact with them via DDL (CREATE, ALTER, DROP) and read them via SELECT.
The USER, ALL, and DBA Hierarchy
Most static data dictionary views are grouped into three prefixes based on scope and permissions.
USER_TABLES: Shows all tables owned by the schema you logged in as.ALL_TABLES: Shows all tables you own, plus tables owned by other schemas that you have been grantedSELECTaccess to.DBA_TABLES: Shows every table in the database, including system tables. You must have theDBArole orSELECT ANY DICTIONARYprivilege to query these.
The Universal Search
If you don't know the exact name of a view, query DICTIONARY (or its synonym DICT).
SELECT * FROM DICT WHERE table_name LIKE '%INDEX%';
Essential Static Views
Here are the most critical views every Oracle developer must know. (We will use the ALL_ prefix, but DBA_ works too).
1. ALL_OBJECTS
The master list. Contains every table, view, procedure, function, trigger, and index you can access.
2. ALL_TAB_COLUMNS
Allows you to search for columns across the entire database. Very useful when you know a column name but forgot which table it lives in.
3. ALL_INDEXES and ALL_IND_COLUMNS
Use these to verify if a query will be performant, or to reverse-engineer access paths.
Dynamic Performance Views (V$)
While DBA_ views show static metadata, V$ views show the live, real-time state of the database memory and processes. They are populated dynamically from memory structures, not from disk.
1. V$SESSION
The most important view for troubleshooting. Shows who is logged in and what they are doing.
2. V$SQL
Shows the actual SQL statements currently cached in the Shared Pool. You can join V$SESSION.SQL_ID to V$SQL.SQL_ID to see exactly what query a user is executing right now!
Generating SQL with SQL
One of the most powerful uses of the Data Dictionary is writing SQL queries that generate other SQL queries.
Imagine you need to drop 50 backup tables that start with TMP_. Instead of writing 50 DROP statements manually, let the dictionary do it:
You can copy-paste the output and execute it, or wrap it in a PL/SQL EXECUTE IMMEDIATE block for full automation.
Common Gotchas
Important Gotchas
- !
Never trust a
COUNT(*)on aV$view. Because these views are windows into live memory, data can change while the query is executing, leading to inconsistent read errors or blocking. - !
Querying
ALL_views is often much slower thanDBA_views. Why? BecauseALL_views have to execute complex internal security checks to verify if you have grants to see every individual object. If you have DBA access, always useDBA_for speed.
Key Takeaways
Key Takeaways
- The Data Dictionary is the ultimate source of truth for database schema metadata.
- Understand the scope prefixes:
USER_(yours),ALL_(granted to you), andDBA_(everything). - Use
V$SESSIONandV$SQLto troubleshoot active performance bottlenecks in real-time. - Leverage the dictionary to generate repetitive DDL scripts dynamically.


