MySQL ISNULL() Function

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 is NULL.
  • It returns a 1 if the expression is NULL and 0 if the expression has a non-NULL value.

Return Value

  • 1: If the expression is NULL.
  • 0: If the expression is not NULL.

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, like SELECT queries, to check if a field or variable contains a NULL value and act accordingly.

Was this article helpful?