Is there a select to determine if I'm currently connected to an Oracle CDB or PDB?
CodePudding user response:
Here is a general solution, using a query.
Each connection has a connection id. The id is 1 for the CDB
and 2 for PDB$SEED
, and >=3 for other connections. (It's 0 for the entire multitenant database.) So:
select case sys_context('USERENV', 'CON_ID')
when '1' then 'CDB' else 'PDB' end
as cdb_or_pdb
from dual;
In specific user interfaces, you can use shortcuts. For example, in SQL*Plus:
show con_id
If it's 1 you are in the CDB, otherwise in a PDB.