-- ===================================================================
-- MARS-1005 Verify Data Integrity: Source vs Exported Data Validation
-- ===================================================================
-- Purpose: Verify data integrity between 6 OU_TOP.LEGACY_* source tables
--          and corresponding ODS external tables after export
-- Author: Grzegorz Michalski
-- Date: 2026-03-06
-- MARS Issue: MARS-1005

SET SERVEROUTPUT ON SIZE UNLIMITED
SET TIMING ON

PROMPT =========================================================================
PROMPT MARS-1005 Data Integrity Verification
PROMPT =========================================================================

-- Check 1: Source table record counts
PROMPT Checking source table record counts (OU_TOP.LEGACY_* tables)...
DECLARE
    v1Rows  NUMBER := 0;  v2Rows  NUMBER := 0;  v3Rows  NUMBER := 0;
    v4Rows  NUMBER := 0;  v5Rows  NUMBER := 0;  v6Rows  NUMBER := 0;
    vTotalRows NUMBER := 0;
BEGIN
    EXECUTE IMMEDIATE 'SELECT COUNT(*) FROM OU_TOP.LEGACY_ALLOTMENT'                     INTO v1Rows;
    EXECUTE IMMEDIATE 'SELECT COUNT(*) FROM OU_TOP.LEGACY_ALLOTMENT_MODIFICATION_HEADER' INTO v2Rows;
    EXECUTE IMMEDIATE 'SELECT COUNT(*) FROM OU_TOP.LEGACY_ALLOTMENT_MODIFICATION_ITEM'   INTO v3Rows;
    EXECUTE IMMEDIATE 'SELECT COUNT(*) FROM OU_TOP.LEGACY_ANNOUNCEMENT'                  INTO v4Rows;
    EXECUTE IMMEDIATE 'SELECT COUNT(*) FROM OU_TOP.LEGACY_FBL_ITEM'                      INTO v5Rows;
    EXECUTE IMMEDIATE 'SELECT COUNT(*) FROM OU_TOP.LEGACY_FULLBID_ARRAY_COMPILED'        INTO v6Rows;

    vTotalRows := v1Rows + v2Rows + v3Rows + v4Rows + v5Rows + v6Rows;

    DBMS_OUTPUT.PUT_LINE('Source table record counts:');
    DBMS_OUTPUT.PUT_LINE('- LEGACY_ALLOTMENT                    : ' || v1Rows || ' records');
    DBMS_OUTPUT.PUT_LINE('- LEGACY_ALLOTMENT_MODIFICATION_HEADER: ' || v2Rows || ' records');
    DBMS_OUTPUT.PUT_LINE('- LEGACY_ALLOTMENT_MODIFICATION_ITEM  : ' || v3Rows || ' records');
    DBMS_OUTPUT.PUT_LINE('- LEGACY_ANNOUNCEMENT                 : ' || v4Rows || ' records');
    DBMS_OUTPUT.PUT_LINE('- LEGACY_FBL_ITEM                     : ' || v5Rows || ' records');
    DBMS_OUTPUT.PUT_LINE('- LEGACY_FULLBID_ARRAY_COMPILED       : ' || v6Rows || ' records');
    DBMS_OUTPUT.PUT_LINE('- TOTAL                               : ' || vTotalRows || ' records');

    IF vTotalRows > 0 THEN
        DBMS_OUTPUT.PUT_LINE('SUCCESS: All source tables contain data');
    ELSE
        DBMS_OUTPUT.PUT_LINE('ERROR: No data found in source tables');
    END IF;
EXCEPTION
    WHEN OTHERS THEN
        DBMS_OUTPUT.PUT_LINE('ERROR: Cannot access source tables: ' || SQLERRM);
        DBMS_OUTPUT.PUT_LINE('NOTE: Ensure SELECT privilege on OU_TOP.LEGACY_* is granted to CT_MRDS');
END;
/

-- Check 2: A_ETL_LOAD_SET_FK distribution across source tables
PROMPT Checking A_ETL_LOAD_SET_FK distribution...
DECLARE
    v1Keys  NUMBER := 0;  v2Keys  NUMBER := 0;  v3Keys  NUMBER := 0;
    v4Keys  NUMBER := 0;  v5Keys  NUMBER := 0;  v6Keys  NUMBER := 0;
    vDistinctAllKeys NUMBER := 0;
BEGIN
    EXECUTE IMMEDIATE 'SELECT COUNT(DISTINCT A_ETL_LOAD_SET_FK) FROM OU_TOP.LEGACY_ALLOTMENT'                     INTO v1Keys;
    EXECUTE IMMEDIATE 'SELECT COUNT(DISTINCT A_ETL_LOAD_SET_FK) FROM OU_TOP.LEGACY_ALLOTMENT_MODIFICATION_HEADER' INTO v2Keys;
    EXECUTE IMMEDIATE 'SELECT COUNT(DISTINCT A_ETL_LOAD_SET_FK) FROM OU_TOP.LEGACY_ALLOTMENT_MODIFICATION_ITEM'   INTO v3Keys;
    EXECUTE IMMEDIATE 'SELECT COUNT(DISTINCT A_ETL_LOAD_SET_FK) FROM OU_TOP.LEGACY_ANNOUNCEMENT'                  INTO v4Keys;
    EXECUTE IMMEDIATE 'SELECT COUNT(DISTINCT A_ETL_LOAD_SET_FK) FROM OU_TOP.LEGACY_FBL_ITEM'                      INTO v5Keys;
    EXECUTE IMMEDIATE 'SELECT COUNT(DISTINCT A_ETL_LOAD_SET_FK) FROM OU_TOP.LEGACY_FULLBID_ARRAY_COMPILED'        INTO v6Keys;

    SELECT COUNT(DISTINCT wk)
    INTO vDistinctAllKeys
    FROM (
        SELECT A_ETL_LOAD_SET_FK AS wk FROM OU_TOP.LEGACY_ALLOTMENT                    UNION ALL
        SELECT A_ETL_LOAD_SET_FK         FROM OU_TOP.LEGACY_ALLOTMENT_MODIFICATION_HEADER UNION ALL
        SELECT A_ETL_LOAD_SET_FK         FROM OU_TOP.LEGACY_ALLOTMENT_MODIFICATION_ITEM   UNION ALL
        SELECT A_ETL_LOAD_SET_FK         FROM OU_TOP.LEGACY_ANNOUNCEMENT                  UNION ALL
        SELECT A_ETL_LOAD_SET_FK         FROM OU_TOP.LEGACY_FBL_ITEM                      UNION ALL
        SELECT A_ETL_LOAD_SET_FK         FROM OU_TOP.LEGACY_FULLBID_ARRAY_COMPILED
    );

    DBMS_OUTPUT.PUT_LINE('Distinct A_ETL_LOAD_SET_FK values per table (source):');
    DBMS_OUTPUT.PUT_LINE('- LEGACY_ALLOTMENT                    : ' || v1Keys);
    DBMS_OUTPUT.PUT_LINE('- LEGACY_ALLOTMENT_MODIFICATION_HEADER: ' || v2Keys);
    DBMS_OUTPUT.PUT_LINE('- LEGACY_ALLOTMENT_MODIFICATION_ITEM  : ' || v3Keys);
    DBMS_OUTPUT.PUT_LINE('- LEGACY_ANNOUNCEMENT                 : ' || v4Keys);
    DBMS_OUTPUT.PUT_LINE('- LEGACY_FBL_ITEM                     : ' || v5Keys);
    DBMS_OUTPUT.PUT_LINE('- LEGACY_FULLBID_ARRAY_COMPILED       : ' || v6Keys);
    DBMS_OUTPUT.PUT_LINE('- Total distinct ETL load keys (all tables): ' || vDistinctAllKeys);

    IF vDistinctAllKeys > 0 THEN
        DBMS_OUTPUT.PUT_LINE('SUCCESS: ETL load key distribution looks normal');
    ELSE
        DBMS_OUTPUT.PUT_LINE('ERROR: No ETL load keys found in source data');
    END IF;
END;
/

-- Check 3: Template table compatibility verification
PROMPT Checking template table compatibility (CT_ET_TEMPLATES.TOP_*)...
DECLARE
    vCols1  NUMBER := 0;  vCols2  NUMBER := 0;  vCols3  NUMBER := 0;
    vCols4  NUMBER := 0;  vCols5  NUMBER := 0;  vCols6  NUMBER := 0;
BEGIN
    SELECT COUNT(*) INTO vCols1
    FROM all_tab_columns WHERE owner = 'CT_ET_TEMPLATES' AND table_name = 'TOP_ALLOTMENT';
    SELECT COUNT(*) INTO vCols2
    FROM all_tab_columns WHERE owner = 'CT_ET_TEMPLATES' AND table_name = 'TOP_ALLOTMENT_MODIFICATION_HEADER';
    SELECT COUNT(*) INTO vCols3
    FROM all_tab_columns WHERE owner = 'CT_ET_TEMPLATES' AND table_name = 'TOP_ALLOTMENT_MODIFICATION_ITEM';
    SELECT COUNT(*) INTO vCols4
    FROM all_tab_columns WHERE owner = 'CT_ET_TEMPLATES' AND table_name = 'TOP_ANNOUNCEMENT';
    SELECT COUNT(*) INTO vCols5
    FROM all_tab_columns WHERE owner = 'CT_ET_TEMPLATES' AND table_name = 'TOP_FULLBIDLIST_ITEM';
    SELECT COUNT(*) INTO vCols6
    FROM all_tab_columns WHERE owner = 'CT_ET_TEMPLATES' AND table_name = 'TOP_FULLBID_ARRAY_COMPILED';

    DBMS_OUTPUT.PUT_LINE('Template table column counts:');
    DBMS_OUTPUT.PUT_LINE('- CT_ET_TEMPLATES.TOP_ALLOTMENT                    : ' || vCols1 || ' columns');
    DBMS_OUTPUT.PUT_LINE('- CT_ET_TEMPLATES.TOP_ALLOTMENT_MODIFICATION_HEADER: ' || vCols2 || ' columns');
    DBMS_OUTPUT.PUT_LINE('- CT_ET_TEMPLATES.TOP_ALLOTMENT_MODIFICATION_ITEM  : ' || vCols3 || ' columns');
    DBMS_OUTPUT.PUT_LINE('- CT_ET_TEMPLATES.TOP_ANNOUNCEMENT                 : ' || vCols4 || ' columns');
    DBMS_OUTPUT.PUT_LINE('- CT_ET_TEMPLATES.TOP_FULLBIDLIST_ITEM             : ' || vCols5 || ' columns');
    DBMS_OUTPUT.PUT_LINE('- CT_ET_TEMPLATES.TOP_FULLBID_ARRAY_COMPILED       : ' || vCols6 || ' columns');

    IF vCols1 > 0 AND vCols2 > 0 AND vCols3 > 0 AND vCols4 > 0 AND vCols5 > 0 AND vCols6 > 0 THEN
        DBMS_OUTPUT.PUT_LINE('SUCCESS: All 6 template tables have defined structure');
    ELSE
        DBMS_OUTPUT.PUT_LINE('ERROR: One or more template tables missing columns');
    END IF;
END;
/

-- Check 4: Verify A_SOURCE_FILE_CONFIG entries for 6 TOP tables
PROMPT Checking A_SOURCE_FILE_CONFIG registration for TOP tables...
DECLARE
    vConfigCount NUMBER := 0;
BEGIN
    SELECT COUNT(*)
    INTO vConfigCount
    FROM CT_MRDS.A_SOURCE_FILE_CONFIG
    WHERE A_SOURCE_FILE_CONFIG_KEY IN (705, 683, 684, 689, 696, 697);  -- MARS-1005 config keys

    DBMS_OUTPUT.PUT_LINE('A_SOURCE_FILE_CONFIG entries for MARS-1005 tables: ' || vConfigCount || ' (expected: 6)');
    DBMS_OUTPUT.PUT_LINE('Config keys: 705(ALLOTMENT), 683(MOD_HDR), 684(MOD_ITEM), 689(ANNOUNCEMENT), 696(FBL_ITEM), 697(FBA_COMPILED)');

    IF vConfigCount = 6 THEN
        DBMS_OUTPUT.PUT_LINE('SUCCESS: All 6 source file config entries confirmed');
    ELSE
        DBMS_OUTPUT.PUT_LINE('ERROR: Missing config entries (' || (6 - vConfigCount) || ' missing)');
    END IF;
END;
/

PROMPT A_SOURCE_FILE_CONFIG details for TOP tables:
SELECT
    A_SOURCE_FILE_CONFIG_KEY,
    TABLE_ID,
    TEMPLATE_TABLE_NAME,
    SUBSTR(SOURCE_FILE_NAME_PATTERN, 1, 40) AS FILE_PATTERN
FROM CT_MRDS.A_SOURCE_FILE_CONFIG
WHERE A_SOURCE_FILE_CONFIG_KEY IN (705, 683, 684, 689, 696, 697)
ORDER BY A_SOURCE_FILE_CONFIG_KEY;

PROMPT =====================================================================================
PROMPT MARS-1005 Record Count Verification
PROMPT =====================================================================================
PROMPT Comparing source table counts with exported external table counts
PROMPT =====================================================================================

DECLARE
    TYPE t_table_info IS RECORD (
        source_schema VARCHAR2(50),
        source_table VARCHAR2(100),
        external_table VARCHAR2(100),
        description VARCHAR2(200)
    );
    TYPE t_table_list IS TABLE OF t_table_info;
    
    vTables t_table_list;
    vSourceCount NUMBER;
    vTargetCount NUMBER;
    vTotalSourceCount NUMBER := 0;
    vTotalTargetCount NUMBER := 0;
    vMismatchCount NUMBER := 0;
    vSql VARCHAR2(4000);
    vFileCount NUMBER := 0;
    vValidationResult VARCHAR2(100);
BEGIN
    DBMS_OUTPUT.PUT_LINE('VERIFICATION TIME: ' || TO_CHAR(SYSTIMESTAMP, 'YYYY-MM-DD HH24:MI:SS'));
    DBMS_OUTPUT.PUT_LINE('');
    
    -- Initialize table list with 6 OU_TOP LEGACY table configuration
    vTables := t_table_list(
        t_table_info('OU_TOP', 'LEGACY_ALLOTMENT',                     'ODS.TOP_ALLOTMENT_ODS',                     'ALLOTMENT data (A_SOURCE_FILE_CONFIG_KEY=705)'),
        t_table_info('OU_TOP', 'LEGACY_ALLOTMENT_MODIFICATION_HEADER', 'ODS.TOP_ALLOTMENT_MODIFICATION_HEADER_ODS', 'MOD HEADER data (A_SOURCE_FILE_CONFIG_KEY=683)'),
        t_table_info('OU_TOP', 'LEGACY_ALLOTMENT_MODIFICATION_ITEM',   'ODS.TOP_ALLOTMENT_MODIFICATION_ITEM_ODS',   'MOD ITEM data (A_SOURCE_FILE_CONFIG_KEY=684)'),
        t_table_info('OU_TOP', 'LEGACY_ANNOUNCEMENT',                  'ODS.TOP_ANNOUNCEMENT_ODS',                  'ANNOUNCEMENT data (A_SOURCE_FILE_CONFIG_KEY=689)'),
        t_table_info('OU_TOP', 'LEGACY_FBL_ITEM',                      'ODS.TOP_FULLBIDLIST_ITEM_ODS',              'FBL ITEM data (A_SOURCE_FILE_CONFIG_KEY=696)'),
        t_table_info('OU_TOP', 'LEGACY_FULLBID_ARRAY_COMPILED',        'ODS.TOP_FULLBID_ARRAY_COMPILED_ODS',        'FBA COMPILED data (A_SOURCE_FILE_CONFIG_KEY=697)')
    );
    
    DBMS_OUTPUT.PUT_LINE('-----------------------------------------------------------------------------------------');
    DBMS_OUTPUT.PUT_LINE('Table Name                Source Count   Target Count   Status');
    DBMS_OUTPUT.PUT_LINE('-----------------------------------------------------------------------------------------');
    
    FOR i IN 1..vTables.COUNT LOOP
        -- Get source table count
        vSql := 'SELECT COUNT(*) FROM ' || vTables(i).source_schema || '.' || vTables(i).source_table;
        
        BEGIN
            EXECUTE IMMEDIATE vSql INTO vSourceCount;
            vTotalSourceCount := vTotalSourceCount + vSourceCount;
        EXCEPTION
            WHEN OTHERS THEN
                vSourceCount := -1;
                DBMS_OUTPUT.PUT_LINE(RPAD(vTables(i).source_table, 24) || 'ERROR: Cannot access source table');
                CONTINUE;
        END;
        
        -- Get target external table count
        vSql := 'SELECT COUNT(*) FROM ' || vTables(i).external_table;
        BEGIN
            EXECUTE IMMEDIATE vSql INTO vTargetCount;
            vTotalTargetCount := vTotalTargetCount + vTargetCount;
        EXCEPTION
            WHEN OTHERS THEN
                -- Handle expected errors for empty external tables
                -- ORA-29913: error in executing ODCIEXTTABLEOPEN callout
                -- ORA-29400: data cartridge error
                -- KUP-13023: nothing matched wildcard query (no files in bucket)
                -- NOTE: ORA-30653 (reject limit) is a real data quality error, not treated as empty
                IF vSourceCount = 0 OR SQLCODE IN (-29913, -29400) OR SQLERRM LIKE '%KUP-13023%' THEN
                    vTargetCount := 0;  -- Treat as empty (no files exported yet)
                ELSE
                    vTargetCount := -1;  -- Real error
                END IF;
        END;
        
        -- Display comparison results with thousands separators
        DECLARE
            vStatus VARCHAR2(20);
            vSourceDisplay VARCHAR2(17);
            vTargetDisplay VARCHAR2(17);
        BEGIN
            -- Format source count display
            IF vSourceCount = -1 THEN
                vSourceDisplay := 'ERROR';
            ELSE
                vSourceDisplay := TO_CHAR(vSourceCount, '9,999,999,999');
            END IF;
            
            -- Format target count display
            IF vTargetCount = -1 THEN
                vTargetDisplay := 'ERROR';
            ELSE
                vTargetDisplay := TO_CHAR(vTargetCount, '9,999,999,999');
            END IF;
            
            -- Determine status
            IF vSourceCount = vTargetCount THEN
                vStatus := 'PASS';
            ELSIF vTargetCount = -1 THEN
                vStatus := 'ERROR';
                vMismatchCount := vMismatchCount + 1;
            ELSIF vSourceCount = -1 THEN
                vStatus := 'ERROR';
                vMismatchCount := vMismatchCount + 1;
            ELSE
                vStatus := 'MISMATCH';
                vMismatchCount := vMismatchCount + 1;
            END IF;
            
            DBMS_OUTPUT.PUT_LINE(
                RPAD(vTables(i).source_table, 24) ||
                LPAD(vSourceDisplay, 15) ||
                LPAD(vTargetDisplay, 15) || '   ' ||
                vStatus
            );
        END;
    END LOOP;
    
    DBMS_OUTPUT.PUT_LINE('-----------------------------------------------------------------------------------------');
    DBMS_OUTPUT.PUT_LINE(
        RPAD('TOTALS', 24) ||
        LPAD(TO_CHAR(vTotalSourceCount, '9,999,999,999'), 15) ||
        LPAD(TO_CHAR(vTotalTargetCount, '9,999,999,999'), 15)
    );
    DBMS_OUTPUT.PUT_LINE('-----------------------------------------------------------------------------------------');
    DBMS_OUTPUT.PUT_LINE('');
    
    -- Count MARS-1005 registered export files
    SELECT COUNT(*)
    INTO vFileCount
    FROM CT_MRDS.A_SOURCE_FILE_RECEIVED
    WHERE PROCESS_NAME = 'MARS-1005'
      AND RECEPTION_DATE >= SYSDATE - 1/24;
    
    DBMS_OUTPUT.PUT_LINE('=====================================================================================');
    DBMS_OUTPUT.PUT_LINE('Record Count Verification Summary');
    DBMS_OUTPUT.PUT_LINE('=====================================================================================');
    DBMS_OUTPUT.PUT_LINE('Total source records: ' || TO_CHAR(vTotalSourceCount, '9,999,999,999'));
    DBMS_OUTPUT.PUT_LINE('Total target records: ' || TO_CHAR(vTotalTargetCount, '9,999,999,999') || ' (exported to ODS)');
    DBMS_OUTPUT.PUT_LINE('Export files registered (PROCESS_NAME=MARS-1005): ' || vFileCount);
    DBMS_OUTPUT.PUT_LINE('');
    
    IF vMismatchCount = 0 AND vFileCount > 0 THEN
        DBMS_OUTPUT.PUT_LINE('[PASS] VERIFICATION PASSED');
        DBMS_OUTPUT.PUT_LINE('  All record counts match between source and exported data');
        DBMS_OUTPUT.PUT_LINE('  Export completed successfully');
    ELSIF vMismatchCount > 0 THEN
        DBMS_OUTPUT.PUT_LINE('[INFO] VERIFICATION COMPLETED WITH MISMATCHES');
        DBMS_OUTPUT.PUT_LINE('  Found ' || vMismatchCount || ' table(s) with count mismatches');
        DBMS_OUTPUT.PUT_LINE('  NOTE: Mismatches may be caused by pre-existing files in buckets (see pre-check)');
        DBMS_OUTPUT.PUT_LINE('  Review export logs and pre-check results before re-running exports');
    ELSE
        DBMS_OUTPUT.PUT_LINE('[WARN] NO EXPORT DETECTED');
        DBMS_OUTPUT.PUT_LINE('  No files found in export registration');
        DBMS_OUTPUT.PUT_LINE('  Verify export execution completed successfully');
    END IF;
    DBMS_OUTPUT.PUT_LINE('=====================================================================================');
    DBMS_OUTPUT.PUT_LINE('');
    
    DBMS_OUTPUT.PUT_LINE('Legend:');
    DBMS_OUTPUT.PUT_LINE('  PASS       - Record counts match (export successful)');
    DBMS_OUTPUT.PUT_LINE('  MISMATCH   - Record counts differ (may be pre-existing files or export issue)');
    DBMS_OUTPUT.PUT_LINE('               Check pre-check results to identify pre-existing files');
    DBMS_OUTPUT.PUT_LINE('  ERROR      - Cannot access table (verify table exists and permissions)');
    DBMS_OUTPUT.PUT_LINE('=====================================================================================');
    
    -- Workflow Key Analysis
    DBMS_OUTPUT.PUT_LINE('');
    DBMS_OUTPUT.PUT_LINE('ETL Load Key Analysis (distinct A_ETL_LOAD_SET_FK per source table):');

    DECLARE
        v1Keys NUMBER;  v2Keys NUMBER;  v3Keys NUMBER;
        v4Keys NUMBER;  v5Keys NUMBER;  v6Keys NUMBER;
    BEGIN
        EXECUTE IMMEDIATE 'SELECT COUNT(DISTINCT A_ETL_LOAD_SET_FK) FROM OU_TOP.LEGACY_ALLOTMENT'                     INTO v1Keys;
        EXECUTE IMMEDIATE 'SELECT COUNT(DISTINCT A_ETL_LOAD_SET_FK) FROM OU_TOP.LEGACY_ALLOTMENT_MODIFICATION_HEADER' INTO v2Keys;
        EXECUTE IMMEDIATE 'SELECT COUNT(DISTINCT A_ETL_LOAD_SET_FK) FROM OU_TOP.LEGACY_ALLOTMENT_MODIFICATION_ITEM'   INTO v3Keys;
        EXECUTE IMMEDIATE 'SELECT COUNT(DISTINCT A_ETL_LOAD_SET_FK) FROM OU_TOP.LEGACY_ANNOUNCEMENT'                  INTO v4Keys;
        EXECUTE IMMEDIATE 'SELECT COUNT(DISTINCT A_ETL_LOAD_SET_FK) FROM OU_TOP.LEGACY_FBL_ITEM'                      INTO v5Keys;
        EXECUTE IMMEDIATE 'SELECT COUNT(DISTINCT A_ETL_LOAD_SET_FK) FROM OU_TOP.LEGACY_FULLBID_ARRAY_COMPILED'        INTO v6Keys;

        DBMS_OUTPUT.PUT_LINE('- LEGACY_ALLOTMENT                    : ' || v1Keys || ' distinct keys');
        DBMS_OUTPUT.PUT_LINE('- LEGACY_ALLOTMENT_MODIFICATION_HEADER: ' || v2Keys || ' distinct keys');
        DBMS_OUTPUT.PUT_LINE('- LEGACY_ALLOTMENT_MODIFICATION_ITEM  : ' || v3Keys || ' distinct keys');
        DBMS_OUTPUT.PUT_LINE('- LEGACY_ANNOUNCEMENT                 : ' || v4Keys || ' distinct keys');
        DBMS_OUTPUT.PUT_LINE('- LEGACY_FBL_ITEM                     : ' || v5Keys || ' distinct keys');
        DBMS_OUTPUT.PUT_LINE('- LEGACY_FULLBID_ARRAY_COMPILED       : ' || v6Keys || ' distinct keys');
        DBMS_OUTPUT.PUT_LINE('- Actual export files registered: ' || vFileCount);
    EXCEPTION
        WHEN OTHERS THEN
            DBMS_OUTPUT.PUT_LINE('WARNING: Cannot query ETL load keys: ' || SQLERRM);
    END;
END;
/

PROMPT =========================================================================
PROMPT Data Integrity Verification Completed
PROMPT =========================================================================