MySQL ISNULL() Function
The ISNULL()
function in MySQL checks if an expression evaluates to NULL
(meaning it doesn't have a value). It's a simple but important function for handling missing data.
ISNULL(): Definition and Usage
This function is useful for conditional logic or data validation. It returns 1 if the expression is NULL
, and 0 otherwise. It helps you to identify and handle situations where a value might be missing.
Syntax
Syntax
ISNULL(expression)
Parameter Values
Parameter | Description |
---|---|
expression |
The value or expression you want to check for NULL . This is required. |
Examples
Testing a NULL Value
This checks if a NULL
value is indeed NULL
.
Syntax
SELECT ISNULL(NULL);
Output
1
Testing an Empty String
An empty string ("") is *not* considered NULL
in MySQL.
Syntax
SELECT ISNULL("");
Output
0
Testing a Numeric Value
A numeric value is also not NULL
.
Syntax
SELECT ISNULL(350);
Output
0
Testing a Non-Empty String
A non-empty string is not NULL
.
Syntax
SELECT ISNULL("Hello world!");
Output
0