我有一个查询在MysqL中工作正常,但是当我在Oracle上运行它得到以下错误:
sql Error: ORA-00933: sql command not properly ended
00933. 00000 – “sql command not properly ended”
查询是:
UPDATE table1 INNER JOIN table2 ON table1.value = table2.DESC SET table1.value = table2.CODE WHERE table1.UPDATETYPE='blah';
该语法在Oracle中无效。你可以这样做:
UPDATE table1 SET table1.value = (SELECT table2.CODE FROM table2 WHERE table1.value = table2.DESC) WHERE table1.UPDATETYPE='blah' AND EXISTS (SELECT table2.CODE FROM table2 WHERE table1.value = table2.DESC);
或者你可以这样做:
UPDATE (SELECT table1.value as OLD,table2.CODE as NEW FROM table1 INNER JOIN table2 ON table1.value = table2.DESC WHERE table1.UPDATETYPE='blah' ) t SET t.OLD = t.NEW
(这取决于内联视图是否被Oracle视为可更新)。