SQL IsNull (oracle,mysql tutorial, MSSQL)
IsNull
Replaces null with the specified replacement value.
Grammar
IsNull (Check_expression, Replacement_value)
Parameters
Check_expression
An expression that will be checked for null. Check_expression can be of any type.
Replacement_value
An expression to be returned when check_expression is null. Replacement_value must be with
Check_expresssion has the same type.
return type
Returns the same type as check_expression.
Comments
Returns the value of the expression if check_expression is not null;
Replacement_value
Example
A. Use ISNULL with Avg
The following example finds the average price of all books and replaces the values in the $10.00 of the titles table with the
All null entries.
Use pubs
Go
Select AVG (IsNull (price, $10.00))
From titles
Go
Let's take a look at other database tutorials
Oracle
Oracle has no 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 (). But the way it works with Microsoft's IsNull () function
A little different.
In MySQL, we can use the ifnull () function, just like this:
Select Productname,unitprice* (Unitsinstock+ifnull (unitsonorder,0))
From Products