How to List Databases in Oracle

Galaxy Glossary

How do I list all databases in Oracle?

List all Oracle databases, CDBs, and PDBs using SQL*Plus or SQL Developer queries on dynamic performance views.

Sign up for the latest in SQL knowledge from the Galaxy Team!
Welcome to the Galaxy, Guardian!
Oops! Something went wrong while submitting the form.

Description

Use dynamic performance views (V$DATABASE, V$PDBS) or the SHOW PDBS command to list all Oracle databases and pluggable databases in a multi-tenant environment.

How do I list the current database?

Run SELECT name FROM v$database; in SQL*Plus or SQL Developer. The query returns the single database name managed by your Oracle instance.

How can I list all Pluggable Databases (PDBs)?

Connect to the container database (CDB$ROOT) and execute SHOW PDBS; or query V$PDBS. Each row represents a PDB that can host its own schemas like Customers and Orders.

Why use V$PDBS instead of SHOW PDBS?

V$PDBS lets you filter, join, and aggregate inside SQL, enabling checks such as the number of PDBs in OPEN mode or joined analytics across environments.

Can I include business context in the query?

Yes. After identifying the target PDB (e.g., ECOM_PDB), switch with ALTER SESSION SET CONTAINER = ECOM_PDB; and run ecommerce queries like SELECT COUNT(*) FROM customers;.

Best practices for listing Oracle databases

Always connect as a common user (e.g., SYS or a DBA role) in the root container. Grant only SET CONTAINER and SELECT privileges required for auditing.

When should I use data dictionary views?

Use DBA_PDBS for metadata available to DBAs, or ALL_PDBS for user-level visibility. These views provide creation times, service names, and open modes in a single call.

Why How to List Databases in Oracle is important

How to List Databases in Oracle Example Usage


-- Step 1: List PDBs to find the ecommerce database
SELECT pdb_name, open_mode FROM v$pdbs;

-- Step 2: Connect to the ecommerce PDB
ALTER SESSION SET CONTAINER = ECOM_PDB;

-- Step 3: Confirm the Customers table exists
SELECT COUNT(*) AS total_customers FROM customers;

How to List Databases in Oracle Syntax


-- List current database
SELECT name FROM v$database;

-- Show all PDBs (quick)
SHOW PDBS;

-- List PDBs with additional metadata
SELECT pdb_name,
       open_mode,
       creation_scn,
       con_id
FROM   v$pdbs
ORDER  BY pdb_name;

-- Switch to a specific ecommerce PDB and verify
ALTER SESSION SET CONTAINER = ECOM_PDB;
SELECT COUNT(*) AS customer_total FROM customers;

Common Mistakes

Frequently Asked Questions (FAQs)

What privilege is required to query V$PDBS?

You need the SELECT_CATALOG_ROLE or explicit SELECT privilege on V_$PDBS.

Can I list databases without SYS access?

Yes. A common user with SET CONTAINER and SELECT on V$PDBS can list PDBs.

Does Oracle store multiple databases per instance?

In non-CDB architecture, one instance hosts one database. In multi-tenant (CDB) mode, an instance hosts one CDB that contains multiple PDBs.

Want to learn about other SQL terms?

Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie
BauHealth Logo
Truvideo Logo
Welcome to the Galaxy, Guardian!
Oops! Something went wrong while submitting the form.