The ISNULL() function in MySQL is used to check if a given expression is NULL. It returns 1 if the expression is NULL, and 0 if the expression is not NULL.
Syntax
ISNULL(expression)
Parameter Values
- expression: The value to test for
NULL.
Definition and Usage
- The
ISNULL()function helps determine whether a particular expression or value isNULL. - It returns a
1if the expression isNULLand0if the expression has a non-NULLvalue.
Return Value
1: If the expression isNULL.0: If the expression is notNULL.
Technical Details
- Works in: From MySQL 4.0
Examples
Example 1: Expression is NULL
Test whether the expression NULL is NULL:
SELECT ISNULL(NULL);
Example Output:
1
Example 2: Expression is an empty string
Test whether the expression "" (empty string) is NULL:
SELECT ISNULL("");
Example Output:
0
Example 3: Expression is a number
Test whether the number 350 is NULL:
SELECT ISNULL(350);
Example Output:
0
Example 4: Expression is a string
Test whether the string "Hello world!" is NULL:
SELECT ISNULL("Hello world!");
Example Output:
0
Usage Notes
ISNULL()is commonly used in conditional logic, likeSELECTqueries, to check if a field or variable contains aNULLvalue and act accordingly.