我的问题很简单。我试图将UPDATE语句转换为MERGE语句以获得更好的性能,因为更新计数可能在10K到1M之间。这是我的更新代码:
UPDATE table_1 t1
SET t1.col_1 =
(SELECT t2.name
FROM table_2 t2
WHERE t2.fn = t1.col_1),
t1.Col_3 =
(SELECT t2.name
FROM table_2 t2
WHERE t2.fn = t1.Col_3),
t1.Col_5 =
(SELECT t2.name
FROM table_2 t2
WHERE t2.fn = t1.Col_5);
我尝试换成MERGE:
MERGE INTO Table_1
USING (SELECT NAME FROM table_2) A
ON (1 = 1)
WHEN MATCHED
THEN
UPDATE SET Table_1.col_1 = A.NAME,
Table_1.col_3 = A.NAME,
Table_1.col_5 = A.NAME;
上面的代码抛出错误,请帮我解决问题。提前谢谢。
答案 0 :(得分:1)
使用
WHEN NOT MATCHED THEN
INSERT (table_1.col1)
VALUES (a.name);