Friday 1 April 2016

SQL NVL2

NVL2 Function we can pass three parameters if first parameter is not null it returns second parameter. if first parameter is null it return third parameter

Syntax:  NVL2 (String1, expr2 , expr3)

Ø If String1 is not null expr2 will return
Ø If String1 is null expr3 will return

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, nvl2(marks,300,100) from student;


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

No comments:

Post a Comment