2012-05-10 210 views
0

我想寫一個更新程序PLSQL更新語句

哪種方法是最好的

1)方法1

if(condition)="P" 

update table 
set fields1 
where field2 = "2" ; 


else(condition)="U" 
update table 
set fields1 
where field3 = "3" ; 

2)方法2

case condition 
    when "p" 
update table 
set fields1 
where field2 = "2" ; 


    when "u" 
    update table 
set fields1 
where field3 = "3" ; 

遇到我應該使用是否有理由使用它,爲什麼另一個不是一個好的選擇。

回答

2
update table t 
    set ... 
    where (condition='P' and field2='2') or (condition='U' and field3='3') 
+0

嗨..不會這個查詢需要更多的時間,如果表是巨大的?因爲每行都必須檢查這些條件。 – Jeevi

0

我會建議你使用CASE,因爲CASE是更有效和可讀性文比較IF。 但是,如果你有小桌子,只有2例來檢查..它沒有任何意義,我認爲..