2012-05-10 207 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例来检查..它没有任何意义,我认为..