--
-- Properly set up C2D UC Dissem
--

-- 1. Create Template table CT_TEMPLTATE_TABLES.C2D_UC_NMA_DISSEM

CREATE TABLE CT_ET_TEMPLATES.C2D_UC_NMA_DISSEM
   AS SELECT * FROM OU_C2D.UC_NMA_DISSEM WHERE 1=2;

-- 2. Create external tables

EXEC CT_MRDS.FILE_MANAGER.CREATE_EXTERNAL_TABLE('C2D_UC_NMA_DISSEM_INBOX','CT_ET_TEMPLATES.C2D_UC_NMA_DISSEM','INBOX/C2D/UC_DISSEM/UC_NMA_DISSEM');
EXEC CT_MRDS.FILE_MANAGER.CREATE_EXTERNAL_TABLE('C2D_UC_NMA_DISSEM_ODS','CT_ET_TEMPLATES.C2D_UC_NMA_DISSEM','ODS/C2D/UC_NMA_DISSEM');
EXEC CT_MRDS.FILE_MANAGER.CREATE_EXTERNAL_TABLE('C2D_UC_NMA_DISSEM_ARCHIVE','CT_ET_TEMPLATES.C2D_UC_NMA_DISSEM','ARCHIVE/C2D/UC_NMA_DISSEM');

-- 3. Export table OU_C2D.UC_NMA_DISSEM

EXEC CT_MRDS.FILE_MANAGER.EXPORT_TABLE_DATA_BY_DATE('OU_C2D','UC_NMA_DISSEM','A_ETL_LOAD_SET_FK','mrds_inbox_tst','ARCHIVE/C2D/UC_NMA_DISSEM');

-- 4. Rename table to legacy table

ALTER TABLE OU_C2D.UC_NMA_DISSEM RENAME TO UC_NMA_DISSEM_LEGACY;

-- 5. Create OU view on top of ODS table

GRANT SELECT ON ods.C2D_UC_NMA_DISSEM_ODS TO OU_C2D;
create or replace view OU_C2D.UC_NMA_DISSEM AS SELECT * from ods.C2D_UC_NMA_DISSEM_ODS;
show errors
