--ENSURE NDC_3 SCRIPT HAS BEEN RUN FIRST BEFORE RUNNING UPDATE!!----------------------------------------------------------

UPDATE ppsnepl.epl_ndcs
   SET package_size = NULL
 WHERE 1 = 1;

ALTER TABLE ppsnepl.epl_ndcs
   MODIFY package_size NUMBER (30, 0);

ALTER TABLE ppsnepl.epl_ndcs RENAME COLUMN package_size TO package_size_id_fk;

UPDATE ppsnepl.epl_ndcs o
   SET o.package_size_id_fk =
          (SELECT MIN (epl_package_sizes.epl_id)
             FROM ppsnepl.epl_package_sizes, ppsnepl.temp_epl_ndcs
            WHERE     epl_package_sizes.package_size =
                         temp_epl_ndcs.package_size
                  AND temp_epl_ndcs.epl_id = o.epl_id)
 WHERE o.epl_id IN (SELECT epl_id FROM ppsnepl.temp_epl_ndcs);

COMMIT;