SET ECHO ON
SET DEFINE ON
column fcltlogfile new_value fcltlogfile NOPRINT;
select UPPER(USER) || '_AAEN#28444_' || to_char(sysdate,'YYYYMMDD_HH24MISS') || '.lst' as fcltlogfile from dual;
spool &fcltlogfile
SET DEFINE OFF


DECLARE
   CURSOR c
   IS
      SELECT mld_opdr_key,
             TO_DATE (SUBSTR (oms, INSTR (oms, 'Opdrachtdatum: ') + 18, 16),
                      'dd-mm-yyyy hh24:mi')
                begindatum
        FROM (SELECT (SELECT MAX (fac_tracking_oms) oms
                        FROM fac_tracking t2, fac_srtnotificatie sn
                       WHERE t2.fac_tracking_refkey = o.mld_opdr_key
                         AND t2.fac_srtnotificatie_key = sn.fac_srtnotificatie_key
                         AND sn.fac_srtnotificatie_code = 'ORDUPD'
                         AND t2.fac_tracking_oms LIKE
                                '%Opdrachtdatum:%-->%08:00%'
                         AND t2.fac_tracking_oms NOT LIKE
                                '%Opdrachtdatum:%08:00 -->%')
                        oms,
                     mld_opdr_key
                FROM mld_opdr o
               WHERE TO_CHAR (o.mld_opdr_datumbegin, 'hh24:mi') = '08:00');
BEGIN
   FOR rec IN c
   LOOP
      BEGIN
         UPDATE mld_opdr
            SET mld_opdr_datumbegin = rec.begindatum
          WHERE mld_opdr_key = rec.mld_opdr_key;
      END;
   END LOOP;
END;
/


BEGIN adm.systrackscriptid('$Id$'); END;
/

COMMIT;
SPOOL OFF
