All technological notes.
We have 2 pluggable databases
pdbx1 which contains schema called x1
x1 schema contain some objects like tables and viewspdbx2, am empty pdbTask:
x1 from pluggable pdbx1 to pluggable database pdbx2x1 to be x2 in the pluggable pdbx2Using Data Pump

Create pluggable pdbx1 using DBCA from seed
pdbx1_adminGrant admin DBA role
sqlplus / as sysdba
show user
--USER is "SYS"
show con_name
--CON_NAME
--------------------------------
--CDB$ROOT
-- verify creation
show pdbs
-- 8 PDBX1 READ WRITE NO
alter session set container=pdbx1;
show con_name
--CON_NAME
--------------------------------
--PDBX1
-- gran privilege
grant create session, dba to pdbx1_admin;
vi $ORACLE_HOME/network/admin/tnsnames.ora
# add:
PDBX1 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = test.com)(PORT = 1521))
)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = pdbx1.com)
)
)
sqlplus pdbx1_admin@pdbx1
show user
show con_name
x1
create user x1 identified by x1;
grant create session, create view, create table, unlimited tablespace to x1;
connect x1/x1@pdbx1
show user
show con_name
create table emp (id number primary key, name varchar2(100));
Insert into emp values (1, ' khaled');
Insert into emp values (2, ' ahmed');
Commit;
Create table dept ( deptno number primary key , name varchar2(100 ) );
Insert into dept values (1, ' sales dept ');
Commit;
-- verify
SELECT count(*) FROM emp;
-- 2
SELECT count(*) FROM dept;
-- 1
Create pluggable pdbx2 using DBCA from seed
pdbx2_adminGrant him DBA role
sqlplus / as sysdba
show user
show con_name
-- verify pdb creation
show pdbs
alter session set container=pdbx2;
show con_name
grant create session, dba to pdbx2_admin;
vi $ORACLE_HOME/network/admin/tnsnames.ora
# add:
PDBX2 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = test.com)(PORT = 1521))
)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = pdbx2.com)
)
)
sqlplus pdbx2_admin/pdbx2_admin@pdbx2
create user x2 identified by x2;
grant create session, create view, create table, unlimited tablespace to x2;
connect x2/x2@pdbx2
show user
show con_name
mkdir /home/oracle/move_pdb
connect pdbx1_admin@pdbx1;
CREATE DIRECTORY d_pdbx1
AS '/home/oracle/move_pdb';
GRANT read, write ON DIRECTORY d_pdbx1 TO x1;
exit
# in terminal
# expdb: a utility of data pump to export database
# with X1 connection
# schema: x1
# directory: use dir to export
# dumpfile: specify the file name for export
expdp x1/x1@pdbx1 SCHEMAS=x1 DIRECTORY=d_pdbx1 DUMPFILE=expx1.dmp

# in terminal
# import the dmp file then output the sql file containing DDL helps in understanding the data in the dmp file
impdp x1/x1@pdbx1 SCHEMAS=x1 DIRECTORY= d_pdbx1 DUMPFILE=expx1.dmp SQLFILE=x1_sql

note:
- All DDL statements are read from the dump file ( not the DML )
- DDL does not include creation of user/schema,
x1.
- This is why must create the schema in target pdb.
- The reason for this is that this dump file is created by x1, the schema which created by sys. So x1’s file cannot include the sql to create its owner.
# import from dump file
# remap to tell oracle to convert schema
impdp pdbx2_admin/pdbx2_admin@pdbx2 REMAP_SCHEMA=x1:x2 DIRECTORY= d_pdbx1 DUMPFILE=expx1.dmp
# ORA-39002: invalid operation
# ORA-39070: Unable to open the log file.
# ORA-39087: directory name D_PDBX1 is invalid
- No such file or directory due to there is no directory created in the target PDB.
sqlplus pdbx2_admin/pdbx2_admin@pdbx2;
CREATE DIRECTORY d_pdbx1
AS '/home/oracle/move_pdb';
# in terminal
# import data from a dump file
impdp pdbx2_admin/pdbx2_admin@pdbx2 REMAP_SCHEMA=x1:x2 DIRECTORY= d_pdbx1 DUMPFILE=expx1.dmp

sqlplus x2/x2@pdbx2
-- verify
SELECT count(*) FROM emp;
-- 2
SELECT count(*) FROM dept;
-- 1
In the above steps, schema is export using x1, a user without DBA role. Therefore, x1 has not privilege to create user.
The following is on top of the above lab, but focus on the exporting schema in the source PDB.
# using pdbx1_admin with DBA role
expdp pdbx1_admin@pdbx1 SCHEMAS=x1 DIRECTORY=d_pdbx1 DUMPFILE=test.dmp

# generate the sql file
impdp pdbx1_admin@pdbx1 SCHEMAS=x1 DIRECTORY=d_pdbx1 DUMPFILE=test.dmp SQLFILE=test_sql


- the sql includes the statement to create user and grant privileges.
impdp pdbx2_admin/pdbx2_admin@pdbx2 REMAP_SCHEMA=x1:x3 DIRECTORY=d_pdbx1 DUMPFILE=test.dmp

- target pdb automatically create user x3
sqlplus pdbx2_admin@pdbx2
show con_name
show user
select count(*) from x3.dept;
-- 1
select count(*) from x3.emp;
-- 2
Comparison: