Below are steps for converting a non CDB/PDB database to PDB database in oracle. i.e Plugging a normal 12c non pdb database to a container database.

 

READ more about CDB and PDB: Oracle 12c Multitenent architecture 

DEMO:

NON-CDB DB -NAME -> NONCDB
CDB DB NAME -> DBATEST

Prerequisites:

 Make sure One container database already exists. 

Check out How to create container database

STEPS:

1. Open the non-cdb database in read only mode:

SQL> select name from v$database;

NAME
---------
NONCDB

SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup open read only
ORACLE instance started.

Total System Global Area 1.8119E+10 bytes
Fixed Size                  7641528 bytes
Variable Size            1.0133E+10 bytes
Database Buffers         7851737088 bytes
Redo Buffers              126574592 bytes
Database mounted.
Database opened.
SQL> select name,open_mode from v$database;

NAME      OPEN_MODE
--------- --------------------
NONCDB    READ ONLY

2. Check the compatibility of PDB on ( NONCDB)

BEGIN
DBMS_PDB.DESCRIBE(pdb_descr_file => '/export/home/oracle/NonCDB.xml');
END;
/

PL/SQL procedure successfully completed.

3. shutdown the NON-CDB database ( NONCDB)

SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> exit

 

Now connect to the container database, where it need to be plugged.

SET SERVEROUTPUT ON;
DECLARE
compatible CONSTANT VARCHAR2(3) := CASE DBMS_PDB.CHECK_PLUG_COMPATIBILITY(pdb_descr_file => '/export/home/oracle/NonCDB.xml')
WHEN TRUE THEN 'YES'
ELSE 'NO'
END;
BEGIN
DBMS_OUTPUT.PUT_LINE(compatible);
END;
/

5. Check the violations:

 select name,cause,type,message,status from PDB_PLUG_IN_VIOLATIONS where name='NONCDB';

NAME                 CAUSE                TYPE
-------------------- -------------------- ---------
MESSAGE                             STATUS
----------------------------------- ---------
NONCDB               Non-CDB to PDB       WARNING
PDB plugged in is a non-CDB,        PENDING
requires noncdb_to_pdb.sql be run.

NONCDB               Parameter            WARNING
CDB parameter memory_target         PENDING
mismatch: Previous 17280M Current
13856M


 

6. Create pluggable database ( DBATEST)

SQL>  create  pluggable database NONCDB using '/export/home/oracle/NonCDB.xml' NOCOPY;
 create  pluggable database NONCDB using '/export/home/oracle/NonCDB.xml' NOCOPY
*
ERROR at line 1:
ORA-27038: created file already exists
ORA-01119: error in creating database file '/archive/NONCDB/temp01.dbf'


--- As tempfile is already there, so mention tempfile reuse tag, to avoid this error.

SQL> create  pluggable database NONCDB using '/export/home/oracle/NonCDB.xml' NOCOPY tempfile reuse;

Pluggable database created.


7 . Run the noncdb_to_pdb.sql script

ALTER SESSION SET CONTAINER=NONCDB;

@$ORACLE_HOME/rdbms/admin/noncdb_to_pdb.sql

8. Open the PDB:

SQL> ALTER PLUGGABLE DATABASE OPEN;

Pluggable database altered.

SQL> SELECT name, open_mode FROM v$pdbs;


NAME                 OPEN_MODE
-------------------- ----------
NONCDB               READ WRITE

1 row selected.


SQL> select name,open_mode from v$pdbs;

NAME                 OPEN_MODE
-------------------- ----------
PDB$SEED             READ ONLY
PDB1                 READ WRITE
PDB2                 READ WRITE
NONCDB               READ WRITE