SQL isnull (oracle, mysql tutorial, mssql)
Isnull
Replace null with the specified replacement value.
Syntax
Isnull (check_expression, replacement_value)
Parameters
Check_expression
Whether the expression is null is checked. Check_expression can be of any type.
Replacement_value
The expression returned when check_expression is null. Replacement_value must be the same
Check_expresssion has the same type.
Return type
Returns the same type as check_expression.
Note
If check_expression is not null, the value of this expression is returned; otherwise
Replacement_value
Example
A. Use isnull With avg
The following example finds the average price of all books and replaces the price column in the titles table with the value $10.00.
All null entries.
Use pubs
Go
Select avg (isnull (price, $10.00 ))
From titles
Go
Next, let's take a look at other database tutorials.
Oracle
Oracle does not have the isnull () function. However, we can use the nvl () function to achieve the same result:
Select productname, unitprice * (unitsinstock + nvl (unitsonorder, 0 ))
From products
Mysql
Mysql also has functions similar to isnull. However, it works with Microsoft's isnull () function.
A little different.
In mysql, we can use the ifnull () function, like this:
Select productname, unitprice * (unitsinstock + ifnull (unitsonorder, 0 ))
From products