C/C++教程

oracle update join

本文主要是介绍oracle update join,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

今天需要写一个根据关联查询结果更新数据的sql,mysql中支持这样的语法:
mysql:
UPDATE T1, T2,
[INNER JOIN | LEFT JOIN] T1 ON T1.C1 = T2. C1
SET T1.C2 = T2.C2,
    T2.C3 = expr
WHERE condition
但是oracle不支持上面的语法,oracle实现上面功能的语法结构如下:
oracle 方式1:
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);
或者
oracle 方式2:
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 update join的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!