DB: Cloning a non-CDB as a PDB

This note describes how to clone a non-CDB as a PDB located on a OCI dbsystem.

#1 From the source non-CDB:

CREATE USER ebs_clone IDENTIFIED BY <password>;
GRANT CREATE SESSION TO ebs_clone;
GRANT CREATE PLUGGABLE DATABASE TO ebs_clone;
ALTER SYSTEM SET local_listener='(ADDRESS=(PROTOCOL=TCP)(HOST=<private ip of the dbsystem>)(PORT=1521))' SCOPE=BOTH SID='*';
ALTER SYSTEM REGISTER;
SHUTDOWN IMMEDIATE;
STARTUP MOUNT;
ALTER DATABASE OPEN READ ONLY;

#2 From the target CDB:

ALTER SESSION SET global_names=FALSE
/
DROP DATABASE LINK ebs_link
/
CREATE DATABASE LINK ebs_link
CONNECT TO ebs_clone IDENTIFIED BY <password> 
USING '(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = <private ip of the dbsystem>)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = <non-CDB service>)))'
/
SELECT COUNT(1) FROM dual@ebs_link
/

#3 Submit the clone (started from the CDB)

ALTER PLUGGABLE DATABASE <pdbname> CLOSE
/
DROP PLUGGABLE DATABASE <pdbname> INCLUDING DATAFILES
/
CREATE PLUGGABLE DATABASE <pdbname> FROM NON$CDB@ebs_link
/
SELECT name, open_mode FROM v$pdbs;
/
select message,time from pdb_plug_in_violations
/

#3 Run non_cdb_to_pdb.sql

ALTER SESSION SET CONTAINER=<pdbname>
@?/rdbms/admin/non_cdb_to_pdb.sql

#4 Run datapatch to level up the PDB

#5 Address plug-in violation

Checkout this note for resolution