我有一个查询,在MySQL工作得很好,但当我在Oracle上运行它时,我得到以下错误:

SQL错误:ORA-00933: SQL命令未正确结束 00933. 00000 - "SQL命令未正确结束"

查询为:

UPDATE table1
INNER JOIN table2 ON table1.value = table2.DESC
SET table1.value = table2.CODE
WHERE table1.UPDATETYPE='blah';

当前回答

对table2使用description而不是desc,

update
  table1
set
  value = (select code from table2 where description = table1.value)
where
  exists (select 1 from table2 where description = table1.value)
  and
  table1.updatetype = 'blah'
;

其他回答

不要使用上面的一些答案。

有些人建议使用嵌套SELECT,不要这样做,它非常慢。如果你有很多记录要更新,使用join,就像这样:

update (select bonus 
        from employee_bonus b 
        inner join employees e on b.employee_id = e.employee_id 
        where e.bonus_eligible = 'N') t
set t.bonus = 0;

更多细节请参见此链接。 http://geekswithblogs.net/WillSmith/archive/2008/06/18/oracle-update-with-join-again.aspx。

另外,确保所有要连接的表上都有主键。

update table1  a 
   set a.col1='Y' 
 where exists(select 1 
                from table2 b
               where a.col1=b.col1 
                 and a.col2=b.col2
             )
UPDATE (SELECT T.FIELD A, S.FIELD B
FROM TABLE_T T INNER JOIN TABLE_S S
ON T.ID = S.ID)
SET B = A;

A和B是别名字段,不需要指向表。

它工作得很好

merge into table1 t1
using (select * from table2) t2
on (t1.empid = t2.empid)
when matched then update set t1.salary = t2.salary

甲骨文基地在这方面做得很好。

https://oracle-base.com/articles/misc/updates-based-on-queries

从这个链接-我使用了上述查询的修改,这对我来说没有作用(答案来自mathguy,它使用rowid)

MERGE /*+ APPEND PARALLEL(8) */ INTO dest_table tt
USING source_table st
ON (tt.identifier = st.identifier)
WHEN MATCHED THEN
  UPDATE SET tt.number = st.number;

这里我有两个表:source和dest,它们都有一个共同的varchar字段,我将源标识字段(PK)添加到dest表中。