122 lines
4.6 KiB
SQL
122 lines
4.6 KiB
SQL
--
|
|
-- $Id$
|
|
--
|
|
-- Script containing customer specific sql statements for the FACILITOR database
|
|
-- Voor dbuser invullen: - indien script voor 1 klant is: 'AADS' (de klantcode, zoals vermeld in fac_version_cust)
|
|
-- - script is voor meerdere klanten: 'AAXX' (de groepcode, zoals vermeld in fac_version_group)
|
|
-- - script is voor meerdere klanten met naam volgens een bepaald patroon: '^AA|^ASMS|^GULU|^NMMS|^RABO|^ZKHM'
|
|
-- Ook als het script gedraaid wordt voor de verkeerde cust wordt er een logfile gemaakt.
|
|
-- (dit in tegenstelling tot sample_xxxx.sql)
|
|
|
|
DEFINE thisfile = 'conn_migratie#67269.SQL'
|
|
DEFINE dbuser = 'CONN'
|
|
|
|
SET ECHO ON
|
|
SET DEFINE ON
|
|
COLUMN fcltlogfile NEW_VALUE fcltlogfile NOPRINT;
|
|
COLUMN fcltcusttxt NEW_VALUE fcltcusttxt NOPRINT;
|
|
WHENEVER SQLERROR CONTINUE;
|
|
SELECT adm.getscriptspoolfile('&thisfile') AS fcltlogfile FROM DUAL;
|
|
SPOOL &fcltlogfile
|
|
WHENEVER SQLERROR EXIT;
|
|
SELECT adm.checkscriptcust('&dbuser') AS fcltcusttxt FROM DUAL;
|
|
WHENEVER SQLERROR CONTINUE;
|
|
---------------------------------------
|
|
PROMPT &fcltcusttxt
|
|
---------------------------------------
|
|
SET DEFINE OFF
|
|
|
|
------ payload begin ------
|
|
|
|
|
|
|
|
-- opschonen contract kenmerken
|
|
DELETE FROM cnt_kenmerkcontract WHERE cnt_contract_key IN (SELECT cnt_contract_key FROM cnt_contract);
|
|
DELETE FROM cnt_kenmerk;
|
|
DELETE FROM cnt_srtkenmerk;
|
|
DELETE FROM fac_kenmerkdomein WHERE fac_kenmerkdomein.fac_kenmerkdomein_module='CNT';
|
|
|
|
-- Contract relaties opschonen
|
|
DELETE FROM cnt_contract_note;
|
|
DELETE FROM cnt_contract_object;
|
|
DELETE FROM cnt_contract_plaats;
|
|
|
|
-- Fac tracking opschonen
|
|
DELETE FROM fac_tracking WHERE fac_tracking.fac_tracking_refkey IN (SELECT cnt_contract_key FROM cnt_contract) AND fac_tracking.fac_srtnotificatie_key IN (SELECT fac_srtnotificatie_key FROM fac_srtnotificatie WHERE LOWER(fac_srtnotificatie_xmlnode)='contract');
|
|
|
|
|
|
-- conracten opschonen
|
|
DELETE FROM cnt_contract;
|
|
|
|
-- contract soorten opschinen
|
|
DELETE FROM cnt_disc_params;
|
|
DELETE FROM ins_tab_discipline WHERE ins_tab_discipline.ins_discipline_module='CNT';
|
|
|
|
|
|
COMMIT;
|
|
|
|
|
|
|
|
DECLARE
|
|
CURSOR sel_im IS
|
|
SELECT * from fac_imp_onrgoed1;
|
|
v_regioKey NUMBER;
|
|
v_regio VARCHAR2(1000) :='';
|
|
v_districtKey NUMBER;
|
|
v_district VARCHAR2(1000) :='';
|
|
|
|
v_count NUMBER;
|
|
BEGIN
|
|
FOR sel IN sel_im
|
|
LOOP
|
|
v_regioKey:=0;
|
|
v_districtKey:=0;
|
|
SELECT COUNT(*) INTO v_count FROM alg_regio where UPPER(alg_regio_omschrijving) = UPPER(sel.alg_regio_omschrijving);
|
|
IF v_count = 0 THEN
|
|
v_regio := sel.alg_regio_omschrijving;
|
|
INSERT INTO alg_regio(alg_regio_omschrijving, alg_regio_upper, alg_regio_aanmaak) VALUES(v_regio, UPPER(v_regio), SYSDATE)
|
|
RETURNING alg_regio_key INTO v_regioKey;
|
|
COMMIT;
|
|
-- DBMS_OUTPUT.put_line ('Regio ' || sel.alg_regio_omschrijving ||'('||v_regioKey||') toegevoegd');
|
|
ELSE
|
|
SELECT alg_regio_key INTO v_regioKey FROM alg_regio where UPPER(alg_regio_omschrijving) = UPPER(sel.alg_regio_omschrijving);
|
|
END IF;
|
|
v_districtKey :=0;
|
|
SELECT COUNT(*) INTO v_count FROM alg_district WHERE UPPER(alg_district_omschrijving) = UPPER(sel.alg_district_omschrijving) AND alg_regio_key=v_regioKey;
|
|
IF v_count=0 THEN
|
|
SELECT alg_regio_key INTO v_regioKey FROM alg_regio WHERE UPPER(alg_regio_omschrijving) = UPPER(sel.alg_regio_omschrijving);
|
|
IF v_regioKey >0 THEN
|
|
v_district := sel.alg_district_omschrijving;
|
|
INSERT INTO alg_district(alg_district_omschrijving, alg_district_upper, alg_district_aanmaak, alg_regio_key) VALUES(v_district, UPPER(v_district), SYSDATE, v_regioKey)
|
|
RETURNING alg_district_key INTO v_districtKey;
|
|
-- DBMS_OUTPUT.put_line ('District ' || sel.alg_district_omschrijving ||'('||v_regioKey||') toegevoegd');
|
|
COMMIT;
|
|
|
|
END IF;
|
|
ELSE
|
|
SELECT alg_district_key INTO v_districtKey FROM alg_district where UPPER(alg_district_omschrijving) = UPPER(sel.alg_district_omschrijving) AND alg_regio_key=v_regioKey ;
|
|
END IF;
|
|
|
|
|
|
UPDATE alg_locatie set alg_district_key = v_districtKey WHERE alg_locatie_code = sel.alg_locatie_code AND alg_locatie_verwijder IS NULL;
|
|
COMMIT;
|
|
-- DBMS_OUTPUT.put_line ('Locatie '||sel.alg_locatie_code||' geupdate aan District' || sel.alg_district_omschrijving ||'('||v_districtKey||') toegevoegd');
|
|
END LOOP;
|
|
|
|
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
|