CSDN博客

img phpnewbie

oracle中的UPDATE FROM 解决方法

发表于2004/10/26 12:21:00  3753人阅读

分类: oracle学习

ORACLE中没有类似SQL SERVER的update from功能

一个解决的办法是

/* Formatted on 2004/10/26 11:15 (Formatter Plus v4.5.2) */
UPDATE tablea a
   SET a.fieldforupdate =
            (SELECT b.fieldsource
               FROM tableb b
              WHERE a.keyfield = b.keyfield)
 WHERE EXISTS (
              SELECT b.fieldsource
                FROM tableb b
               WHERE a.keyfield = b.keyfield)



例子

表text

  fielda                fieldb               fieldc
  1                2004-1-1        2004-2-1 
  2                2004-2-2        2004-3-1
  3                2004-3-1        2004-4-1

如果要根据记录2的b字段值更新记录1的c字段值则可以使用如下sql

/* Formatted on 2004/10/26 11:25 (Formatter Plus v4.5.2) */
UPDATE text a
   SET a.fieldb = (SELECT b.fieldb
                     FROM text b
                    WHERE a.fielda = b.fielda
                      AND b.fieldb > a.fieldb
                      AND   b.fieldb
                          - a.fieldb <= 35)
 WHERE EXISTS ( SELECT b.fieldb
                  FROM text b
                 WHERE a.fielda = b.fielda
                   AND b.fieldb > a.fieldb
                   AND   b.fieldb
                       - a.fieldb <= 35)



阅读全文
0 0

相关文章推荐

img
取 消
img