2013-01-25 87 views
0

如何獲取此Postgres語句以解析Oracle 11g?Postgres to Oracle翻譯

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

@LeorA:爲什麼你認爲這是一個觸發器? –

回答

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 

這假定子選擇只會RET每個名稱/縣/ is_old組合爲單行。

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