--
-- $Id$
--
-- Customer specific once-script BLCC#55498.SQL.

DEFINE thisfile = 'BLCC#55498.SQL'
DEFINE dbuser   = '^BLCC'

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 ------

SET SERVEROUTPUT ON size 1000000;

DECLARE
   CURSOR c_wp
   IS
        SELECT '[' || pf.prs_perslid_naam_friendly || '] ' aanduiding,
               pf.prs_perslid_key
          FROM prs_v_perslid_fullnames pf
         WHERE NOT EXISTS (SELECT 1
                             FROM prs_perslidwerkplek
                            WHERE prs_perslid_key = pf.prs_perslid_key)
               AND NOT EXISTS (SELECT 1
                                 FROM prs_perslid
                                WHERE SUBSTR (prs_perslid_oslogin, 1, 1) = '_'
                                      AND prs_perslid_key = pf.prs_perslid_key)
      ORDER BY prs_perslid_key;

   v_errormsg       VARCHAR2 (1000);
   oracle_err_num   NUMBER;
   oracle_err_mes   VARCHAR2 (200);
   v_count          NUMBER;
BEGIN
   v_count := 0;

   FOR rec IN c_wp
   LOOP
      BEGIN
         v_errormsg := 'Fout verhuizen naar fictieve werkplek';
         PRS.movetoruimte (rec.prs_perslid_key, 6001, 'L'); -- Fictieve ruimte in fictief gebouw!
         v_count := v_count + 1;
      EXCEPTION
         WHEN OTHERS
         THEN
            oracle_err_num := SQLCODE;
            oracle_err_mes := SUBSTR (SQLERRM, 1, 200);
            v_errormsg := v_errormsg || ' ORACLE (error ' || oracle_err_num || '/' || oracle_err_mes || ')';
            DBMS_OUTPUT.PUT_LINE ('W: ' || rec.aanduiding || v_errormsg);
            COMMIT;
      END;
   END LOOP;

   DBMS_OUTPUT.PUT_LINE ('S: ' || TO_CHAR (v_count) || ' WPs aangemaakt/toegekend');
   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
