1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| CREATE OR REPLACE PROCEDURE APPLYCHANGES(I_strSourceSchema IN VARCHAR2,I_strDestSchema IN VARCHAR2)
AS
[...] Déclaration des curseurs etc.
BEGIN
-- Init :
j := 0;
-- ******* Disable all triggers & foreign keys :
-- je tape dans ALL_constraints etc. puis je build/exécute le ddl dans cette fonction :
ENABLE_TABLES_FK_AND_TRIGGERS(0,I_strDestSchema);
SELECT t.table_name BULK COLLECT INTO colTables FROM all_tables t
WHERE t.owner = I_strSourceSchema
AND ...
FOR i IN colTables.FIRST..colTables.LAST LOOP
strTableName := colTables(i);
strInsertSubQuery_D := '';
strInsertSubQuery_S := '';
-- 1st, make a massive update/insert using the MERGE INTO statement
-- 2nd, delete the elements removed from intermediate model by, for instance, a baseline restore
strDeleteQuery := 'DELETE FROM ' || I_strDestSchema || '.' || strTableName || ' d WHERE (';
strQuery := 'MERGE INTO ' || I_strDestSchema || '.' || strTableName || ' d ' ||
'USING (SELECT ';
-- [...] Compilation de la requêtes
-- DML execution started : :
j := 1;
EXECUTE IMMEDIATE strDeleteQuery;
EXECUTE IMMEDIATE strQuery;
END LOOP;
j := 2;
-- ******* Re-enable all triggers & foreign keys :
ENABLE_TABLES_FK_AND_TRIGGERS(1,I_strDestSchema);
EXCEPTION
WHEN OTHERS THEN
IF j = 1 THEN
ROLLBACK;
ELSIF j = 2 THEN
RAISE_APPLICATION_ERROR(-20001,'Erreur lors de la réactivation des contraintes + triggers, vérifiez l''intégrité de la base destination de la réplication');
ELSE
RAISE;
END IF;
END;
/ |
Partager