2016-07-21 24 views
0

例如,我需要更新3行。我做的是運行UPDATE語句3時更新每一行:更新多行,1個oracle程序中有許多不同的值

UPDATE table SET col1 = 'a' where col2 = '1'; 
UPDATE table SET col1 = 'b' where col2 = '2'; 
UPDATE table SET col1 = 'c' where col2 = '3'; 

那麼,有沒有辦法讓它更快,謝謝

回答

1

update s爲一個非常合理的做法。你也可以這樣做:

update table 
    set col1 = (case when col2 = 1 then 'a' 
        when col2 = 2 then 'b' 
        when col2 = 3 then 'c' 
        else col1 
       end) 
    where col2 in (1, 2, 3); 
+0

對於'where'子句,'case'表達式的'else'部分是不必要的(它不會傷害,但它不是必需的)。 – mathguy

+0

我想使用sp,所以我可以從我的應用程序調用,你可以建議我帶參數sp – JimmyN

相關問題