General function of oracle study notes

1. NVL(exp1,exp2)

--If the value of the first parameter is not bearish, return the value of the first parameter; otherwise, return the value of the second parameter.


SQL> select NVL(1000,12) FROM DUAL;

NVL(1000,12)
------------
        1000

SQL> select NVL(null,12) FROM DUAL;

NVL(NULL,12)
------------

          12


二、NVL2(exp1,exp2,exp3)

--If the value of the first parameter is not empty, return the value of the second parameter; otherwise, return the value of the third parameter.

 

SQL> SELECT NVL2(12,1,-1) FROM dual;

NVL2(12,1,-1)
-------------
            1

SQL> SELECT NVL2(null,1,-1) FROM dual;

NVL2(NULL,1,-1)
---------------

             -1


Three, NULLIF (exp1, exp2)

--If exp1 and exp2 are equal, return null; otherwise, return exp1.


SQL> SELECT NULLIF(12,12) FROM dual;

NULLIF(12,12)
-------------


SQL> SELECT NULLIF(12,2) FROM dual;

NULLIF(12,2)
------------
          12

 

四、COALESCE(exp1,exp2,exp3,.......expn)

--The function is similar to NVL, except that he indicates that exp1 is empty, then look at exp2, otherwise return exp1; similarly, if exp2 is also empty, return exp3, otherwise, return xep2;. . . .

 

SQL> SELECT COALESCE(null,3,4,null) FROM dual;

COALESCE(NULL,3,4,NULL)
-----------------------
                      3

SQL> SELECT COALESCE(null,null,4,null) FROM dual;

COALESCE(NULL,NULL,4,NULL)
--------------------------
                         4

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326053492&siteId=291194637