/* Pre-requisites: Step 2 on application root and application seed has to be completed.*/
SET VERIFY ON
SET HEAD ON
SET FEEDBACK 1
SET ARRAY 1
SET LINESIZE 10000
SET PAGESIZE 50000
SET LONG 10000
SET ECHO ON
SET TRIMSPOOL ON
SET COLSEP ';'
SET SERVEROUT OFF
clear screen
SPOOL ON
SET SQLBLANKLINES ON
SET SERVEROUTPUT ON
SET ERRORLOGGING ON
SET ECHO ON
prompt Welcome to Application PDB Configuration
SPOOL "&SPOOL_PATH"
/* Inputs are recieved */
/* Connect Approot as sys user */
accept P_CDB_USER Prompt 'Enter CDB Username: '
accept P_CDB_PWD Prompt  'Enter CDB Password: '
accept P_CDB_HOST Prompt 'Enter CDB Host: '
accept P_CDB_PORT Prompt 'Enter CDB Port: '
accept P_CDB_NAME Prompt 'Enter CDB Schema Name: '
accept P_DB_MOUNTED_PATH Prompt 'Enter Approot mounted path for approot application seed creation: [Eg: /scratch/db1800dat]'

accept P_APPROOT_NAME Prompt 'Enter Application Root Name: '
accept P_APPPDB_NAME Prompt 'Please provide name for Application PDB Name -- Application Root associated PDB: '

/* Connecting to Application Root As SYSDBA*/
conn &P_CDB_USER/&P_CDB_PWD@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=&P_CDB_HOST)(PORT=&P_CDB_PORT)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=&P_APPROOT_NAME))) as sysdba;

/* Creating Application Associated PDB*/
CREATE pluggable database &P_APPPDB_NAME FROM &P_APPROOT_NAME$SEED file_name_convert=('&P_DB_MOUNTED_PATH/&P_CDB_NAME/SEED&P_APPROOT_NAME/','&P_DB_MOUNTED_PATH/&P_APPROOT_NAME/&P_APPPDB_NAME/');
ALTER pluggable database &P_APPPDB_NAME OPEN;

SET ERRORLOGGING OFF
SPOOL OFF