Oracle CON_ Functions

Translate between container names, container IDs, DBIDs, UIDs, and GUIDs in a container database with the eight CON_ functions.

An Oracle database is a container database (CDB) holding pluggable databases (PDBs). Each container has several identifiers: a name such as FREEPDB1, a container ID (CON_ID) such as 3, a DBID, a unique ID (UID), and a GUID. Data dictionary views and monitoring tools report different ones, so eight CON_ functions convert between them.

Code for This Guide

The main example is in the examples/environment-functions folder of the Oracle Database 26ai code repository on GitHub, with its output. The repository also has the NIMBUS sample schema in the setup/nimbus folder.

It comes from Oracle Database 26ai SQL and PL/SQL Book.

Syntax

Syntax:

con_name_to_id(name)        con_id_to_con_name(con_id)
con_id_to_dbid(con_id)      con_dbid_to_id(dbid)
con_id_to_uid(con_id)       con_uid_to_id(uid)
con_id_to_guid(con_id)      con_guid_to_id(guid)
IdentifierMeaning
NameThe container's name, such as CDB$ROOT or FREEPDB1
CON_IDThe number of the container within this CDB: 1 for the root, 2 for the seed, 3 and up for PDBs
DBIDThe database identifier of the container
UIDA unique identifier of the PDB
GUIDA globally unique identifier, kept when a PDB is unplugged and plugged in elsewhere

Convert Between Identifiers

The first query starts from the name and the CON_ID of FREEPDB1 and converts in both directions; the second goes through the GUID and UID and back.

Example:

select con_name_to_id('FREEPDB1')          as con_id,
       con_id_to_con_name(3)              as con_name,
       con_id_to_dbid(3)                  as dbid,
       con_dbid_to_id(con_id_to_dbid(3))  as back_to_id,
       con_id_to_uid(3)                   as uid_value
from   dual;

select con_id_to_guid(3) as guid, con_guid_to_id(con_id_to_guid(3)) as from_guid,
       con_uid_to_id(con_id_to_uid(3)) as from_uid
from   dual;

Output:

   CON_ID CON_NAME             DBID    BACK_TO_ID     UID_VALUE
_________ ___________ _____________ _____________ _____________
        3 FREEPDB1       3461734982             3    3461734982

GUID                                   FROM_GUID    FROM_UID
___________________________________ ____________ ___________
5621983B6DFB0909E0630B00580A528D               3           3

FREEPDB1 is container 3. Each round trip returns to 3, confirming that the conversions are inverse. Your DBID, UID, and GUID values will differ.

Where They Help

  • CDB_ data dictionary views, queried in the root, have a CON_ID column; CON_ID_TO_CON_NAME turns it into a readable name, as in select con_id_to_con_name(con_id) as pdb, count(*) from cdb_tables group by con_id.
  • Performance views (V$) also carry CON_ID, so the same conversion labels their rows.
  • Backup and monitoring tools often record a DBID or GUID; CON_DBID_TO_ID and CON_GUID_TO_ID find the container it belongs to.

Inside a PDB, sys_context('USERENV', 'CON_NAME') and sys_context('USERENV', 'CON_ID') return the current container directly.

Related Guides

Conclusion

The CON_ functions convert between the name, container ID, DBID, UID, and GUID of the containers in a CDB. Use them to label CDB_ and V$ views by PDB name and to find the container that a DBID or GUID refers to.

Vinish Kapoor
Vinish Kapoor

An Oracle ACE, author of four books on Oracle APEX, SQL and PL/SQL, and Oracle Forms, and a software developer building Oracle database applications since 2001.

guest

0 Comments
Oldest
Newest Most Voted