ISNULL
ISNULL is a SQL function utilized for handling null values. It takes two arguments and returns the first argument if it is not NULL; else it returns the second argument. It is used to replace NULL values with a specified replacement value.
ISNULL( check_expression , replacement_value )
- check_expression: This is the expression to be checked for NULL. It can be of any of the supported data types in SQL Server.
- replacement_value: This is the value to return if check_expression is NULL. This should be of the same data type as the check_expression, or an error will be thrown.
Example
Output
Explanation
The ISNULL function in SQL server replaces NULL values with a specified replacement value. In the example code, NULL is replaced with ‘Replacement Value’, which is then displayed as the output.
ISNULL(expression)
- expression: This is the expression to be checked for NULL. It can consist of a single column, a computation involving columns, or a string. ISNULL(expression) returns 1 if the expression is NULL, and 0 if it’s not.
Example
Output
Explanation
This example demonstrates the use of the ISNULL function in SQL. The ISNULL function checks whether a value is NULL or not. If the value is NULL, it returns 1; otherwise it returns 0. In the given example, ISNULL checks for NULL and since it is NULL, the output is 1.
ISNULL(value, replacement_value)
- value: The expression to be tested for NULL values. It could be a column name, expression, or a scalar function.
- replacement_value: The replacement value to return if the first argument, value, is found to be NULL. This must be of the same data type as the first argument.
Example
Output
Explanation
The ISNULL
function in Oracle checks whether the given expression is NULL
. If it is, the function returns the substitute value specified. If it’s not NULL
, it returns the expression’s value itself. In this example, because we pass NULL
as the initial value, ‘Replacement Value’ is returned.