DROP SNAPSHOT LOG ON SOURCE.ABC;
丟棄來源資料庫的 SNAPSHOT LOG
DROP MATERIALIZED VIEW DESTINATION.TPE_ABC;
丟棄目的端資料庫的 DROP MATERIALIZED VIEW
CREATE MATERIALIZED VIEW LOG ON SOURCE.ABC
TABLESPACE SOURCE_MLOG
WITH PRIMARY KEY;
在來源資料庫建立 MATERIALIZED VIEW LOG
CREATE MATERIALIZED VIEW DESTINATION.TPE_ABC
TABLESPACE TPE
NOLOGGING
BUILD DEFERRED
USING INDEX TABLESPACE TPE_I
REFRESH FAST
NEXT SYSDATE + 1/2
WITH PRIMARY KEY
AS SELECT
A, B, C, D,
ROWID AS SOURCE_ROWID
FROM SOURCE.ABC@SOURCE_DATABASE;
由來源資料庫建立 MATERIALIZED VIEW
CREATE TRIGGER "DESTINATION"."TR_TPE_ABC"
AFTER INSERT OR UPDATE OR DELETE OF
"A", "B", "C", "D"
ON "DESTINATION"."TPE_ABC"
FOR EACH ROW
BEGIN
IF ( DELETING OR UPDATING ) THEN
DELETE ABC WHERE SOURCE_DB = 'SOURCE_DATABASE'
AND A = :OLD.A;
END IF;
IF INSERTING OR UPDATING THEN
INSERT INTO ALL_ABC
( A, B, C, D, SOURCE_DB, SOURCE_ROWID, REC_SEQ_NO)
VALUES
( :NEW.A, :NEW.B, :NEW.C, :NEW.D, 'SOURCE_DATABASE', :NEW.SOURCE_ROWID, SEQ_SOURCE_DATABASE.NEXTVAL);
END IF;
建立 Trigger 當資料有異動時寫入
沒有留言:
張貼留言