Postgres到Oracle的翻译

时间:2013-01-25 01:41:54

标签: database oracle postgresql syntax

如何将此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;

提前致谢。

3 个答案:

答案 0 :(得分:1)

答案 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