SQL > SQL NULL > NVL Function

The NVL( ) function is available in Oracle, and not in MySQL or SQL Server. This function is used to replace NULL value with another value. It is similar to the IFNULL Function in MySQL and the ISNULL Function in SQL Server.

For example, if we have the following table,

Table Sales_Data

 Store_Name  Sales 
 Store A 300 
 Store B NULL 
 Store C 150 

The following SQL,

SELECT SUM(NVL(Sales,100)) FROM Sales_Data;

would generate result below:

SUM(NVL(Sales,100))
550

This is because NULL has been replaced by 100 via the NVL function, hence the sum of the 3 rows is 300 + 100 + 150 = 550.

Next: SQL COALESCE Function

This page was last updated on June 19, 2023.




Copyright © 2024   1keydata.com   All Rights Reserved     Privacy Policy     About   Contact