Oracle Merge - 我可以做类似 "When Not Matched Then Delete" 的事情吗?
Oracle Merge - Can I do something like "When Not Matched Then Delete"?
我有一个 table (t1),其中包含唯一的患者列表。我有另一个 table (t1_Backup),其中包含重复的患者和详细信息列表。我想本质上执行一个内部连接来更新 t1,它为 t1_Backup 中包含的详细信息列设置了空值。 t1_Backup 还有一些记录我要在加入中删除。
MERGE INTO t1
USING (SELECT * FROM
(SELECT t1_Backup.*
,RANK() OVER (PARTITION BY Patient_ID ORDER BY Col1 DESC, Col2 DESC, ...) AS Pick
FROM t1_Backup
WHERE Active_Status = 'A')
WHERE Pick = 1)
t2 ON (t1.Patient_ID = t2.Patient_ID)
WHEN MATCHED THEN UPDATE
SET
t1.Col1 = t2.Col2
t1.Col2 = t2.Col2
....
ad infinitum(不是字面上的意思,但正如您可能猜到的那样,我只是在更新大量的列——整个练习是从 t2 中删除重复项的精心尝试。数据很复杂,但如果有人对其他方面有建议方法我洗耳恭听。)
对于那些密切关注的人,您可能已经注意到 Active_Status = 'A'
标准可能会产生限制性影响,导致我有一些 Patient_IDs 没有更新。鉴于我的要求,我实际上想简单地将这些行放在一个 swift 中,整齐的步骤。
简而言之,我的问题是是否可以添加一行代码,例如 WHEN NOT MATCHED THEN DELETE
?
我想知道在 运行 发生类似事情之前会发生什么。谢谢!
Specify the DELETE where_clause to clean up data in a table while populating or updating it. The only rows affected by this clause are those rows in the destination table that are updated by the merge operation. The DELETE WHERE condition evaluates the updated value, not the original value that was evaluated by the UPDATE SET ... WHERE condition. If a row of the destination table meets the DELETE condition but is not included in the join defined by the ON clause, then it is not deleted. Any delete triggers defined on the target table will be activated for each row deletion.
我有一个 table (t1),其中包含唯一的患者列表。我有另一个 table (t1_Backup),其中包含重复的患者和详细信息列表。我想本质上执行一个内部连接来更新 t1,它为 t1_Backup 中包含的详细信息列设置了空值。 t1_Backup 还有一些记录我要在加入中删除。
MERGE INTO t1
USING (SELECT * FROM
(SELECT t1_Backup.*
,RANK() OVER (PARTITION BY Patient_ID ORDER BY Col1 DESC, Col2 DESC, ...) AS Pick
FROM t1_Backup
WHERE Active_Status = 'A')
WHERE Pick = 1)
t2 ON (t1.Patient_ID = t2.Patient_ID)
WHEN MATCHED THEN UPDATE
SET
t1.Col1 = t2.Col2
t1.Col2 = t2.Col2
....
ad infinitum(不是字面上的意思,但正如您可能猜到的那样,我只是在更新大量的列——整个练习是从 t2 中删除重复项的精心尝试。数据很复杂,但如果有人对其他方面有建议方法我洗耳恭听。)
对于那些密切关注的人,您可能已经注意到 Active_Status = 'A'
标准可能会产生限制性影响,导致我有一些 Patient_IDs 没有更新。鉴于我的要求,我实际上想简单地将这些行放在一个 swift 中,整齐的步骤。
简而言之,我的问题是是否可以添加一行代码,例如 WHEN NOT MATCHED THEN DELETE
?
我想知道在 运行 发生类似事情之前会发生什么。谢谢!
Specify the DELETE where_clause to clean up data in a table while populating or updating it. The only rows affected by this clause are those rows in the destination table that are updated by the merge operation. The DELETE WHERE condition evaluates the updated value, not the original value that was evaluated by the UPDATE SET ... WHERE condition. If a row of the destination table meets the DELETE condition but is not included in the join defined by the ON clause, then it is not deleted. Any delete triggers defined on the target table will be activated for each row deletion.