SQL22 min readBy Priyanshu Pandey

SQL Masterclass: Mastering the Oracle Data Dictionary

Learn how to query Oracle's metadata using ALL_, DBA_, and V$ views. Discover how to dynamically generate scripts and troubleshoot database performance.

Administration Guide · SQL Masterclass

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.

22 min read📅August 7, 2026✍️Priyanshu Pandey📚SQL Masterclass

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 View Prefix System

The USER, ALL, and DBA Hierarchy

Most static data dictionary views are grouped into three prefixes based on scope and permissions.

  1. USER_TABLES: Shows all tables owned by the schema you logged in as.
  2. ALL_TABLES: Shows all tables you own, plus tables owned by other schemas that you have been granted SELECT access to.
  3. DBA_TABLES: Shows every table in the database, including system tables. You must have the DBA role or SELECT ANY DICTIONARY privilege 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.

Find recently created or modified objects
SQL
SELECT object_name, object_type, last_ddl_time, status 
FROM all_objects 
WHERE owner = 'RMS' 
ORDER BY last_ddl_time DESC;

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.

Find all tables containing an 'ITEM' column
SQL
SELECT table_name, data_type, data_length 
FROM all_tab_columns 
WHERE column_name = 'ITEM' AND owner = 'RMS';

3. ALL_INDEXES and ALL_IND_COLUMNS

Use these to verify if a query will be performant, or to reverse-engineer access paths.

Find all columns indexed for a specific table, in order
SQL
SELECT i.index_name, c.column_name, c.column_position
FROM all_indexes i
JOIN all_ind_columns c ON i.index_name = c.index_name
WHERE i.table_name = 'ITEM_MASTER'
ORDER BY i.index_name, c.column_position;
Live Monitoring

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.

Find active sessions holding locks or running long queries
SQL
SELECT sid, serial#, username, status, machine, sql_id
FROM v$session
WHERE status = 'ACTIVE' AND username IS NOT NULL;

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!

SQL
SELECT sql_text, executions, elapsed_time/1000000 as seconds
FROM v$sql
WHERE sql_id = '7v9a1b2c3d4e5';

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:

SQL
SELECT 'DROP TABLE ' || table_name || ' CASCADE CONSTRAINTS;' 
FROM user_tables 
WHERE table_name LIKE 'TMP_%';

-- Output:
-- DROP TABLE TMP_SALES_2024 CASCADE CONSTRAINTS;
-- DROP TABLE TMP_INVENTORY_BAK CASCADE CONSTRAINTS;

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 a V$ 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 than DBA_ views. Why? Because ALL_ 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 use DBA_ 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), and DBA_ (everything).
  • Use V$SESSION and V$SQL to troubleshoot active performance bottlenecks in real-time.
  • Leverage the dictionary to generate repetitive DDL scripts dynamically.
RetailCoder
All systems operational
v1.0 Live

RC:OMS

Multi-channel order management with double-entry inventory ledger. Amazon, Flipkart, Shopify, WooCommerce — one source of truth.

Launch demo →
v1.0 Live

RC:Storefront

Self-hosted headless e-commerce. Your server, your data, zero transaction fees. Native RC:OMS inventory sync.

Visit Storefront →
Pipeline

RC:Pulse

AI-powered retail analytics and demand forecasting — built natively on top of your RC:OMS and Storefront data.

Request early access →
Built in India 🇮🇳  ·  Architected by Priyanshu PandeyTalk to an engineer →