-- ============================================================================
-- MARS-826 Export Step 01: ADHOC_ADJ Tables
-- ============================================================================
-- Purpose: Export ADHOC_ADJ table group to HIST bucket
-- Author: Grzegorz Michalski
-- Tables: 3 tables (~209 records total)
-- Target: mrds_hist_dev/ARCHIVE/LM/LM_ADHOC_ADJUSTMENTS_*
-- ============================================================================

SET SERVEROUTPUT ON SIZE UNLIMITED

PROMPT
PROMPT ============================================================================
PROMPT Step 01: Exporting ADHOC_ADJ Tables (3 tables)
PROMPT ============================================================================

-- Table 1: LEGACY_ADHOC_ADJ_HEADER (~5 records)
PROMPT
PROMPT Exporting OU_LM.LEGACY_ADHOC_ADJ_HEADER...
BEGIN
    CT_MRDS.DATA_EXPORTER.EXPORT_TABLE_DATA_BY_DATE(
        pSchemaName => 'OU_LM',
        pTableName => 'LEGACY_ADHOC_ADJ_HEADER',
        pKeyColumnName => 'A_ETL_LOAD_SET_KEY_FK',
        pBucketArea => 'ARCHIVE',
        pFolderName => 'ARCHIVE/LM/LM_ADHOC_ADJUSTMENTS_HEADER',
        pParallelDegree => 1,
        pTemplateTableName => 'CT_ET_TEMPLATES.LM_ADHOC_ADJUSTMENTS_HEADER',
        pJobClass => 'high'
    );
    DBMS_OUTPUT.PUT_LINE('SUCCESS: LEGACY_ADHOC_ADJ_HEADER exported');
EXCEPTION
    WHEN OTHERS THEN
        DBMS_OUTPUT.PUT_LINE('ERROR exporting ADHOC_ADJ_HEADER: ' || SQLERRM);
        RAISE;
END;
/

-- Table 2: LEGACY_ADHOC_ADJ_ITEM (~102 records)
PROMPT
PROMPT Exporting OU_LM.LEGACY_ADHOC_ADJ_ITEM...
BEGIN
    CT_MRDS.DATA_EXPORTER.EXPORT_TABLE_DATA_BY_DATE(
        pSchemaName => 'OU_LM',
        pTableName => 'LEGACY_ADHOC_ADJ_ITEM',
        pKeyColumnName => 'A_ETL_LOAD_SET_KEY_FK',
        pBucketArea => 'ARCHIVE',
        pFolderName => 'ARCHIVE/LM/LM_ADHOC_ADJUSTMENTS_ITEM',
        pParallelDegree => 1,
        pTemplateTableName => 'CT_ET_TEMPLATES.LM_ADHOC_ADJUSTMENTS_ITEM',
        pJobClass => 'high'
    );
    DBMS_OUTPUT.PUT_LINE('SUCCESS: LEGACY_ADHOC_ADJ_ITEM exported');
EXCEPTION
    WHEN OTHERS THEN
        DBMS_OUTPUT.PUT_LINE('ERROR exporting ADHOC_ADJ_ITEM: ' || SQLERRM);
        RAISE;
END;
/

-- Table 3: LEGACY_ADHOC_ADJ_ITEM_HEADER (~102 records)
PROMPT
PROMPT Exporting OU_LM.LEGACY_ADHOC_ADJ_ITEM_HEADER...
BEGIN
    CT_MRDS.DATA_EXPORTER.EXPORT_TABLE_DATA_BY_DATE(
        pSchemaName => 'OU_LM',
        pTableName => 'LEGACY_ADHOC_ADJ_ITEM_HEADER',
        pKeyColumnName => 'A_ETL_LOAD_SET_KEY_FK',
        pBucketArea => 'ARCHIVE',
        pFolderName => 'ARCHIVE/LM/LM_ADHOC_ADJUSTMENTS_ITEM_HEADER',
        pParallelDegree => 1,
        pTemplateTableName => 'CT_ET_TEMPLATES.LM_ADHOC_ADJUSTMENTS_ITEM_HEADER',
        pJobClass => 'high'
    );
    DBMS_OUTPUT.PUT_LINE('SUCCESS: LEGACY_ADHOC_ADJ_ITEM_HEADER exported');
EXCEPTION
    WHEN OTHERS THEN
        DBMS_OUTPUT.PUT_LINE('ERROR exporting ADHOC_ADJ_ITEM_HEADER: ' || SQLERRM);
        RAISE;
END;
/

PROMPT
PROMPT Step 01 completed: All ADHOC_ADJ tables exported
PROMPT
