MERGE INTO table_a PARTITION (x) A
USING (SELECT distinct col1,col2 FROM table_b)b
ON (A.col1=B.col1(+) AND A.col2=B.col2(+))
WHEN MATCHED THEN
UPDATE SET col3='Y'
WHEN NOT MATCHED THEN
UPDATE SET col3='N';
问问题
176 次
1 回答
0
该WHEN NOT MATCHED
子句无法执行UPDATE
- 如果没有找到,它应该更新哪些行?
如果要根据 B 中是否存在现有行来更新 A,一种方法是将 A 拉入合并查询(假设您的表 A 具有主键 PK):
MERGE INTO table_a PARTITION (x) tgt
USING (
SELECT A.PK, B.col1, B.col2
FROM table_a A
LEFT JOIN table_b b ON A.col1 = B.col1 AND A.col2 = B.col2) src
ON (src.pk = tgt.pk)
WHEN MATCHED THEN
UPDATE SET col3 = (CASE WHEN src.col1 IS NOT NULL THEN 'Y' ELSE 'N' END);
于 2015-05-20T08:30:29.827 回答