--
-- $Id$
--
-- Verwijder ruimten in Rotterdam ToZ

DEFINE thisfile = 'YKPN#52131.sql'
DEFINE dbuser   = '^YKPN'

SET ECHO ON
SET DEFINE ON
COLUMN fcltlogfile NEW_VALUE fcltlogfile NOPRINT;
WHENEVER SQLERROR EXIT;
SELECT adm.scriptspoolfile('&dbuser', '&thisfile') AS fcltlogfile FROM DUAL;
WHENEVER SQLERROR CONTINUE;
SPOOL &fcltlogfile
SET DEFINE OFF

------ payload begin ------

BEGIN
    fac.initsession ('NL');
END;
/

DECLARE
    CURSOR c
    IS
        SELECT *
          FROM alg_v_ruimte_gegevens
         WHERE alg_gebouw_upper = '37633';

    oracle_err_num   NUMBER;
    oracle_err_mes   VARCHAR2 (200);
    v_errormsg       VARCHAR2 (200);
BEGIN
    FOR rec IN c
    LOOP
        BEGIN
            UPDATE alg_ruimte
               SET alg_ruimte_verwijder = SYSDATE
             WHERE alg_ruimte_key = rec.alg_ruimte_key;
        EXCEPTION
            WHEN OTHERS
            THEN
               UPDATE alg_ruimte
                  SET alg_ruimte_nr = '_' || alg_ruimte_nr
                WHERE alg_ruimte_key = rec.alg_ruimte_key
                  AND SUBSTR(alg_ruimte_nr, 1,1) <> '_';

                oracle_err_num := SQLCODE;
                oracle_err_mes := SUBSTR (SQLERRM, 1, 100);
                v_errormsg :=
                       'OTHERS (error '
                    || oracle_err_num
                    || '/'
                    || oracle_err_mes
                    || ')';


                fac.writelog (
                    'RUIMTE ToZ VERWIJDEREN',
                    'E',
                       'Fout tijdens het verwijderen van ruimte: '
                    || rec.alg_ruimte_aanduiding,
                    v_errormsg);
        END;
    END LOOP;

    COMMIT;
END;
/

------ payload end   ------

SET DEFINE OFF
BEGIN adm.systrackscriptId ('$Id$', 1); END;
/

COMMIT;
SET ECHO OFF
SPOOL OFF
SET DEFINE ON
PROMPT Logfile of this upgrade is: &fcltlogfile
