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.
精彩评论