oracle中if/else、decode函数、case when

来源:互联网 发布:无网络远程监控 编辑:程序博客网 时间:2024/05/22 15:51

1、标准sql规范

复制代码
一、单个IF1if a=...  then.........end if;2if a=... then......else....end if;二、多个IFif 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='1'then 'xxxx'     when a='2' then 'ssss'else
  'zzzzz'
end as

注意点: 

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

0 0