zoukankan      html  css  js  c++  java
  • Oracle中的4大空值处理函数用法举例

    nvl(exp1,exp2):                           如果exp1为空,则返回exp2;否则返回exp1
    nvl2(exp1,exp2,exp3):                 如果exp1为空,则返回exp3;否则返回exp2
    nullif(exp1,exp2):                         如果exp1等于exp2,则返回空;否则返回exp1
    coalesce(exp1,exp2.....expn):     返回列表中第1个不为空的值,如果全部元素为空,则返回空。

    举例说明如下:

    SQL> select nvl(1,2) from dual;
     
      NVL(1,2)
    ----------
             1
     
    SQL> select nvl(null,2) from dual;
     
    NVL(NULL,2)
    -----------
              2
     
    SQL> select nvl2(2,3,4) from dual;
     
    NVL2(2,3,4)
    -----------
              3
     
    SQL> select nvl2(null,3,4) from dual;
     
    NVL2(NULL,3,4)
    --------------
                 4
     
    SQL> select nullif(5,4) from dual;
     
    NULLIF(5,4)
    -----------
              5
     
    SQL> select nullif(5,5) from dual;
     
    NULLIF(5,5)
    -----------     
    
    SQL> select coalesce(null,1,null,2,3) from dual;
     
    COALESCE(NULL,1,NULL,2,3)
    -------------------------
                            1
     
    SQL> select coalesce(null,null,null,2,3) from dual;
     
    COALESCE(NULL,NULL,NULL,2,3)
    ----------------------------
                               2
    
    此外case和decode也可以处理空值。
  • 相关阅读:
    05-浮动/css
    04-选择器/css
    03-样式表/css
    02-html标签&表格&表单
    01-html基础&标签
    vue分页组件重置到首页问题
    VUE通过索引值获取数据不渲染的问题
    常见IE8兼容性问题及解决
    Ajax
    sea.js模块化工具
  • 原文地址:https://www.cnblogs.com/huangbiquan/p/7795143.html
Copyright © 2011-2022 走看看