Wednesday, January 1, 2025

What is the NVL equivalent in SQL Server?

 In SQL Server, the equivalent of Oracle's NVL function is the ISNULL function.

  • Oracle NVL(expr1, expr2): This function returns expr2 if expr1 is NULL; otherwise, it returns expr1.

  • SQL Server ISNULL(expr1, expr2): This function works similarly. It returns expr2 if expr1 is NULL; otherwise, it returns expr1.

Example

Oracle:

SELECT NVL(column_name, 'Default Value') FROM table_name;

SQL Server:

SELECT ISNULL(column_name, 'Default Value') FROM table_name;

Both expressions would replace NULL values in the column_name with 'Default Value'.

No comments:

Post a Comment