当前位置: 移动技术网 > IT编程>数据库>Oracle > 在oracle中if/else功能的实现教程

在oracle中if/else功能的实现教程

2018年09月29日  | 移动技术网IT编程  | 我要评论
一、单个if 1、 if a=...  then ......... end if; 2、 if a=... then ...... else .... end if; 二、多个if if

一、单个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='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 后跟别名  

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网