如何将此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;
提前致谢。
答案 0 :(得分:1)
您似乎希望使用联接执行更新,即UPDATE ... FROM
。这似乎不是直接支持的,但可以使用带有子查询的UPDATE
来完成。
请参阅:
答案 1 :(得分:0)
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组合返回一行。
答案 2 :(得分:0)
一种方便的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