SQL ORACLE ORA-00969:缺少 ON 关键字?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7577480/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 00:20:06  来源:igfitidea点击:

SQL ORACLE ORA-00969: missing ON keyword?

sqloracle

提问by sailaja

I have two different tables : Table_a and Table_b, both have same columns PartNo and Material_Desc. I want the Material_Desc in Table_b to update the Material_Desc in Table_a when PartNo are equals. This is my query

我有两个不同的表: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;

I know Oracle doesn't support joins for update statement so I tried the above query. Still it gives me ORACLE ORA-00969: missing ON keyword error

我知道 Oracle 不支持更新语句的连接,所以我尝试了上面的查询。它仍然给我 ORACLE ORA-00969:缺少 ON 关键字错误

采纳答案by rudrirk

You might put "(" and ")". So write :

您可以输入“(”和“)”。所以写:

ON (rowid = rid )

rowid = 摆脱

回答by Dan

First of all, the syntax problem: when you merge using a subquery, you have to alias it to something. But more importantly, you don't need to use a subquery.

首先,语法问题:当您使用子查询进行合并时,您必须将其别名为某物。但更重要的是,您不需要使用子查询。

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

First of all, you have to put the table you want to update into the INTOportion. Second, doing the join in a subselect and merging on rowids won't offer you any benefit that I can think of.

首先,您必须将要更新的表放入该INTO部分。其次,在子选择中加入并在 rowids 上合并不会为您提供我能想到的任何好处。

回答by schurik

perhaps not as efficient as a merge statment, but should do the work:

也许不如合并语句有效,但应该可以完成以下工作:

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
                   )