如何让这个 Postgres 语句解析为 Oracle 11g?
UPDATE teams as new
SET counter=old.counter,
task_counter=old.task_counter
FROM teams as old
WHERE new.is_old=0
AND old.is_old=1
AND new.name=old.name
AND new.county=old.county;
提前致谢。
如何让这个 Postgres 语句解析为 Oracle 11g?
UPDATE teams as new
SET counter=old.counter,
task_counter=old.task_counter
FROM teams as old
WHERE new.is_old=0
AND old.is_old=1
AND new.name=old.name
AND new.county=old.county;
提前致谢。
看来您想使用连接执行更新,即UPDATE ... FROM
. 这似乎没有直接支持,但可以使用UPDATE
子查询来完成。
看:
UPDATE teams
SET (counter, task_counter) = (select counter, task_counter
FROM teams old
WHERE old.is_old = 1
AND teams.name = old.name
AND teams.county = old.county)
where is_old = 0
这假定子选择将只为每个 name/county/is_old 组合返回一行。
一种方便的 Oracle 技术是对这些棘手的更新使用 MERGE。
Merge into teams new
From (
Select counter,
task_counter
From teams
Where is_old = 1) old
On (new.is_old = 0 and
new.name = old.name and
new.county = old.county )
when matched then update
set counter = old.counter and
task_counter = old.task_counter