开发者

Oracle Select before update

In Oracle is there way to select a data set and use it for update like in the Merge statement.

I'm looking for something like

USING
(
SELECT a, b, c FROM t
)
UPDATE t1
SET t1.x = t.a,
t1.y = t.b;开发者_开发技巧


It sounds like you just want to

UPDATE t1
   SET (x, y) = (SELECT a, b
                   FROM t
                  WHERE t.some_column = t1.some_column);

If you only want to update rows in T1 if there is a matching row in T

UPDATE t1
   SET (x, y) = (SELECT a, b
                   FROM t
                  WHERE t.some_column = t1.some_column)
 WHERE EXISTS (
   SELECT 1
     FROM t
    WHERE t.some_column = t1.some_column );

If your SELECT from T returns a single row, you can omit the WHERE clause that joins the two tables.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜