我正在尝试对 Oracle 中的 6000 万条记录进行 CDC。 我需要根据目标 (TABLE) 检查 6000 万条源 (TABLE_TEMP) 记录,并执行插入、更新或软删除操作。 我尝试编写单独的查询并执行它们,但这需要很长时间(超过 4 小时)。
这是我已经尝试过的事情:
INSERT INTO TABLE (WID,A,B,C,DELETE_INDICATOR,DELETION_TIME,F,G,H)
SELECT A,B,C,DELETE_INDICATOR,DELETION_TIME,F,G,H FROM
TABLE_TEMP
LEFT OUTER JOIN TABLE ON TABLE.A = TABLE_TEMP.A AND TABLE.B = TABLE_TEMP.B AND TABLE.C = TABLE_TEMP.C
WHERE TABLE.ID IS NULL
WID 是序列
UPDATE TABLE DELETE_INDICATOR = 'Y' ,
DELETION_TIME = TO_DATE(CURRENT_DATE),
F = 'XXX' ,
F = 'YYY' WHERE WID IN ( SELECT DISTINCT
WID
TABLE
LEFT OUTER JOIN TABLE_TEMP
ON TABLE.A = TABLE_TEMP.A AND TABLE.B = TABLE_TEMP.B AND TABLE.C = TABLE_TEMP.C AND TABLE.DELETE_INDICATOR = 'N'
WHERE TABLE_TEMP.A IS NULL AND TABLE_TEMP.B IS NULL )
` UPDATE TABLE SET DELETE_INDICATOR = 'N' ,
DELETION_TIME = TO_DATE(TO_DATE('29991231','YYYYMMDD')),
F = 'XXX' ,
G = 'YYY'
WHERE WID IN ( SELECT DISTINCT
WID
FROM TABLE
LEFT OUTER JOIN TABLE_TEMP
ON TABLE.A = TABLE_TEMP.A AND TABLE.B = TABLE_TEMP.B AND TABLE.C = TABLE_TEMP.C AND DELETE_INDICATOR = 'Y'
WHERE TABLE_TEMP.A IS NULL AND TABLE_TEMP.B IS NULL )`
我也尝试编写 ORACLE MERGE,但这也需要 4 个多小时。
任何人都可以建议更快地完成此操作的最佳方法。