在Oracle上使用inner join更新语句

前端之家收集整理的这篇文章主要介绍了在Oracle上使用inner join更新语句前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个查询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视为可更新)。

猜你在找的Oracle相关文章