0

如何让这个 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;

提前致谢。

4

3 回答 3

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 组合返回一行。

于 2013-01-25T08:34:47.530 回答
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
于 2013-01-25T09:04:39.490 回答