Open In App

SQL general functions | NVL, NVL2, DECODE, COALESCE, NULLIF, LNNVL and NANVL

In this article, we’ll be discussing some powerful SQL general functions, which are – NVL, NVL2, DECODE, COALESCE, NULLIF, LNNVL and NANVL.

These functions work with any data type and pertain to the use of null values in the expression list. These are all single row function i.e. provide one result per row.



SELECT COUNT(*) FROM employees 
  WHERE LNNVL(commission_pct >= .2); 

Output :

  • NANVL() : The NANVL function is useful only for floating-point numbers of type BINARY_FLOAT or BINARY_DOUBLE. It instructs the Database to return an alternative value n2 if the input value n1 is NaN (not a number). If n1 is not NaN, then database returns n1. This function is useful for mapping NaN values to NULL.

    Syntax –

    NANVL( n1 , n2 )

    Consider the following table named nanvl_demo :

    Example –

    SELECT bin_float, NANVL(bin_float,0)
      FROM nanvl_demo;
    

    Output :

  • Reference: Introduction to Oracle9i SQL(Volume-1 Book)

    Article Tags :