Oracle nvl2 function

Description:

  • The Oracle NVL2 function extends the functionality of NVL function. 
  • NVL2 function lets you substitutes values for both null and non-null values encountered.

Syntax:

NVL2( arg1, value_when_not_NULL, value_when_NULL )

arg1:   The string to test for a null value.
value_when_not_NULL:   The value returned if string1 is not null.
value_when_NULL:   The value returned if string1 is null.

  • The NVL2 function returns a substituted value.

Example:

select NVL2(comm, ‘eligible’, ‘not eligible’) from emp;

Here the SQL statement will return  ‘eligible’ for the employees who is having a not_NULL value for comm column, Or else it will return the ‘not eligible’.

Leave a Comment

Your email address will not be published. Required fields are marked *

Twitter
YouTube
Pinterest
LinkedIn