-- ============================================================================
-- MARS-826 Export Step 04: STANDING_FACILITY Tables
-- ============================================================================
-- Purpose: Export STANDING_FACILITY table group to HIST bucket
-- Author: Grzegorz Michalski
-- Tables: 2 tables (~1.2M records total - LARGE DATASET)
-- Target: mrds_hist_dev/ARCHIVE/LM/LM_STANDING_FACILITIES*
-- ============================================================================

SET SERVEROUTPUT ON SIZE UNLIMITED

PROMPT
PROMPT ============================================================================
PROMPT Step 04: Exporting STANDING_FACILITY Tables (2 tables, ~1.2M records)
PROMPT WARNING: Large dataset - this may take significant time
PROMPT ============================================================================

-- START TIMING
PROMPT
SELECT 'START_TIME: ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH24:MI:SS') AS TIMING FROM DUAL;

-- Table 1: LEGACY_STANDING_FACILITY (~1,205,002 records - VERY LARGE)
PROMPT
PROMPT Exporting OU_LM.LEGACY_STANDING_FACILITY (LARGE TABLE ~1.2M records)...
BEGIN
    CT_MRDS.DATA_EXPORTER.EXPORT_TABLE_DATA_BY_DATE(
        pSchemaName => 'OU_LM',
        pTableName => 'LEGACY_STANDING_FACILITY',
        pKeyColumnName => 'A_ETL_LOAD_SET_FK',
        pBucketArea => 'ARCHIVE',
        pFolderName => 'ARCHIVE/LM/LM_STANDING_FACILITIES',
        pParallelDegree => 8,
        pTemplateTableName => 'CT_ET_TEMPLATES.LM_STANDING_FACILITIES',
        pJobClass => 'high'
    );
    DBMS_OUTPUT.PUT_LINE('SUCCESS: LEGACY_STANDING_FACILITY exported');
EXCEPTION
    WHEN OTHERS THEN
        DBMS_OUTPUT.PUT_LINE('ERROR exporting STANDING_FACILITY: ' || SQLERRM);
        RAISE;
END;
/

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

-- END TIMING
PROMPT
SELECT 'END_TIME: ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH24:MI:SS') AS TIMING FROM DUAL;

PROMPT
PROMPT Step 04 completed: All STANDING_FACILITY tables exported
PROMPT
