2
UPDATE
  (
    SELECT
      a.COL1
    FROM
      TABLE1 a,
      TABLE2 b,
      TABLE3 c
    WHERE
      a.name = b.name
      c.ccol = b.ccol AND
      AND b.col1 = 'anyvalue'
      AND a.col2 = 'anothervalue'
  ) u
SET
  u.COL1 = 'VALUE'

此查询不起作用,因为 TABLE1 不包含 PK。如何编写这样的查询?

4

2 回答 2

3

以下应该实现您在上面尝试实现的目标:

UPDATE  TABLE1
SET     COL1 = 'VALUE'
WHERE   EXISTS
        (   SELECT  1
            FROM    TABLE2 B
                    INNER JOIN TABLE3 C
                        ON B.Ccol = C.Ccol
            WHERE   b.Name = Table1.Name
            AND     b.Col1 = 'AnyValue'
            AND     c.Col1 = 'AnotherValue'
        )
于 2012-08-07T14:41:01.217 回答
0

我从未在 oracle 工作过,但尝试这样的事情。只要您的 join & where 语句正确,没有 pk 应该不是问题。

这是您要求的 SQL 等价物

UPDATE u
  SET  u.COL1 = 'VALUE'
  FROM Table1 AS u
  INNER JOIN Table2 AS b ON u.name  = b.name 
  INNER JOIN Table3 AS c ON c.ccol  = b.ccol 
 WHERE b.col1 = 'anyvalue'  AND u.col2 = 'anothervalue'
于 2012-08-07T14:41:11.870 回答