当前位置:Gxlcms > 数据库问题 > oracle中if/else功能的实现的3种写法

oracle中if/else功能的实现的3种写法

时间:2021-07-01 10:21:17 帮助过:2人阅读

一、单个IF --1、 if a=... then ......... end if; --2、 if a=... then ...... else .... end if; --二、多个IF if a=.. then ...... elsif a=.. then .... end if; ----这里中间是“ELSIF”,而不是ELSE IF 。这里需要特别注意

2、decode函数

DECODE的语法

DECODE(value,if1,then1,if2,then2,if3,then3,...,else)

表示如果value等于if1时,DECODE函数的结果返回then1,...,如果不等于任何一个if值,则返回else。

3、case when

case when a=1then xxxx
     when a=2 then ssss
else
  zzzzz
end as

注意点: 

1、以CASE开头,以END结尾 
2、分支中WHEN 后跟条件,THEN为显示结果 
3、ELSE 为除此之外的默认情况,类似于高级语言程序中switch case的default,可以不加 
4、END 后跟别名 

oracle中if/else功能的实现的3种写法

标签:

人气教程排行