Oracle case when的用法

  1. select col1, col2,   
  2.     case  
  3.         when col3 > 1 and col3 <2   
  4.             then '1'   
  5.         when col3 > 2 and col3 <3   
  6.             then '2'   
  7.         when col3 > 3 and col3 <4   
  8.             then '3'   
  9.         else '4'   
  10.     end mycol   
  11. from table1  

注意点:
1、以case开头,以end结尾;
2、分支中when后跟条件,then为显示结果;
3、else为除此之外的默认情况,类似于高级语言程序中switch case的default,可以不加;
4、end后跟别名。

  1. da shang
    donate-alipay
               donate-weixin weixinpay

发表评论↓↓