NVL和NVL2有什么区别,NULLIF 的使用.

  • Post author:
  • Post category:其他


NVL (expr1, expr2):expr1为NULL,返回expr2;不为NULL,返回expr1。注意两者的类型要一致

NVL2 (expr1, expr2, expr3) :xpr1不为NULL,返回expr2;为NULL,返回expr3。expr2和expr3类型不同的话,expr3会转换为expr2的类型

NULLIF (expr1, expr2):相等返回NULL,不等返回expr1

例如:

NVL:

SQL> select nvl(null, 1) from dual;

NVL(NULL,1)

———–

1

SQL> select nvl(2, 1) from dual;

NVL(2,1)

———-

2

NVL2:

SQL> select nvl2(2, 1, 3) from dual;

NVL2(2,1,3)

———–

1

SQL> select nvl2(null, 1, 3) from dual;

NVL2(NULL,1,3)

————–

3

NULLIF:

SQL> select NULLIF(1,1) from dual;

NULLIF(1,1)

———–


SQL> select NULLIF(1,2) from dual;

NULLIF(1,2)

———–

1