Thursday, 31 March 2016

SQL NVL

This will substitutes the specified value in the place of null values.

     Syntax: nvl (null_col, replacement_value) 

     Ex:
          SQL> select * from student;            -- here for 3rd row marks value is null

                         NO NAME      MARKS
                           --- -------      ---------
                          1        a         100
                          2        b          200
                          3        c

SQL> select no, name, nvl(marks,300) from student; 

                        NO NAME  NVL(MARKS,300)
                         ---  -------  ---------------------
                          1           a             100
                          2           b             200
                          3           c             300

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

                NVL(1,2)   NVL(2,3)   NVL(4,3)   NVL(5,4)
               ----------    ----------    ----------         ----------
                      1               2                    4                   5

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

            NVL(0,0)   NVL(1,1) NVL(null,null)  NVL(4,4)
             ----------    ---------- -----------------       ----------

                      0              1                                             4

No comments:

Post a Comment