我有两个不同的表:Table_a和Table_b,它们都具有相同的列PartNo和Material_Desc。当PartNo等于时,我希望Table_b中的Material_Desc更新Table_a中的Material_Desc。这是我的查询
MERGE INTO Table_b
USING ( SELECT t1.rowid AS rid
, t2.Material_Desc
FROM Table_b t1
JOIN Table_a t2
ON Table_b.PartNo = Table_a.PartNo )
ON rowid = rid
WHEN MATCHED THEN
UPDATE
SET Table_a.Material_Desc = Table_b.Material_Desc;
我知道Oracle不支持update语句的连接,所以我尝试了上面的查询。它仍然给了我ORACLE ORA-00969:缺少ON关键字错误
答案 0 :(得分:8)
您可以输入“(”和“)”。所以写:
ON ( rowid = rid )
答案 1 :(得分:2)
首先,语法问题:当您使用子查询进行合并时,您必须将其别名。但更重要的是,您不需要使用子查询。
MERGE INTO Table_a USING Table_b ON (Table_a.PartNo = Table_b.PartNo)
WHEN MATCHED THEN UPDATE SET Table_a.Material_Desc = Table_b.Material_Desc
首先,您必须将要更新的表放入INTO
部分。其次,在子选择中加入并合并rowid不会为你提供任何我能想到的好处。
答案 2 :(得分:0)
可能没有合并声明那么有效,但应该做的工作:
update table_b tb
set tb.Material_Desc = (select ta.Material_Desc
from table_a ta
where ta.PartNo = tb.PartNo
and rownum = 1
)
where tb.rowid in (
SELECT t1.rowid
FROM Table_b t1
, Table_a t2
WHERE t1.PartNo = t2.PartNo
)