
Connecting to CDB and PDB in Oracle Using Easy Connect Syntax
When a Container Database (CDB) is created in Oracle, a service is automatically created with the same name as the CDB. Similarly, when a Pluggable Database (PDB) is created within the CDB, a corresponding service is created with metadata recorded in the PDB. These services are unique across the entire CDB.
You can use the Easy Connect syntax to connect to the root or a PDB unless a net service name is configured in the tnsnames.ora file for the respective service.
Connecting to the CDB Root
To connect to the root container, follow these steps:
1. Use the Easy Connect Syntax
. oraenv
[enter cdb1 at the prompt]
sqlplus sys/oracle@localhost:1521/cdb1 as sysdba
SHOW CON_NAME
SHOW CON_ID
2. Use OS Authentication
Alternatively, connect to the root container using OS authentication:
CONNECT / AS SYSDBA
SHOW CON_NAME
SHOW CON_ID
Listing Available Services
To display the list of available services for the root container and its PDBs, run the following query:
SELECT name, con_id FROM v$active_services ORDER BY 1;
Connecting to a PDB
Use the Easy Connect syntax to connect to a specific PDB unless a net service name is configured in the tnsnames.ora file for the PDB service:
CONNECT sys/oracle@localhost:1521/pdb1 AS SYSDBA
SHOW CON_NAME
SHOW CON_ID
EXIT
Conclusion
Using Easy Connect syntax provides a simple and direct way to connect to the root or specific PDBs in a CDB without requiring a pre-configured net service name. This approach is especially useful for quick access and testing purposes. Always ensure that service names are unique within the CDB to avoid connectivity issues.







