我打算做什么?
要更新一些目标表字段,以匹配匹配的目标记录的子集,并在源和目标之间匹配,只要它们都是同一个表即可。
我需要帮助?
Merge-into-
target -using-select-
source -on-
子句似乎仅对两个类别进行控制 -
- 当源和目标记录匹配时,更新所有匹配目标记录
- 当源和目标记录不匹配时,插入或执行其他控制操作。
在我的情况下,当源和目标记录匹配时,我想在上执行更新,不是全部目标记录,而是在目标记录的子集上进行更新。
请求帮助指导。
用于参考以下是代码(目标过滤器预选赛评论,因为它无法确定):
MERGE INTO TGT
USING (
SELECT id, account_number, part_role, inc_val, pay_frequency,
period, pay_option, inclusion_value
FROM Table_1
WHERE id = var1
AND account_number = var2
AND part_role in ('YY','XX')
) SRC
ON (
SRC.id = TGT.id
AND SRC.account_number = TGT.account_number
--TGT.part_role in ('AA','BB','CC','DD','EE') --This must be a wrong place for this qualifier, please help on where to include this qualifier for filtering out target records for update purpose
)
WHEN MATCHED THEN
UPDATE SET
TGT.inc_val = SRC.inc_val
,TGT.pay_frequency = SRC.pay_frequency
,TGT.period = SRC.period
,TGT.pay_option = SRC.pay_option
,TGT.inclusion_value = SRC.inclusion_value;
其他关联的详细信息
数据库:Oracle
版本:11gr2
环境:unix
添加 where
子句SET
语句。
MERGE INTO TGT
USING (SELECT
id,
account_number,
part_role,
inc_val,
pay_frequency,
period,
pay_option,
inclusion_value
FROM Table_1
WHERE id = var1
AND account_number = var2
AND part_role IN ('YY', 'XX')) SRC
ON (
SRC.id = TGT.id
AND SRC.account_number = TGT.account_number
--TGT.part_role in ('AA','BB','CC','DD','EE') --This must be a wrong place for this qualifier, please help on where to include this qualifier for filtering out target records for update purpose
)
WHEN MATCHED THEN
UPDATE SET
TGT.inc_val = SRC.inc_val
, TGT.pay_frequency = SRC.pay_frequency
, TGT.period = SRC.period
, TGT.pay_option = SRC.pay_option
, TGT.inclusion_value = SRC.inclusion_value
WHERE TGT.part_role in ('AA','BB','CC','DD','EE');