Home > Database > Mysql Tutorial > body text

How to use IFNULL, NULLIF and ISNULL in MySql

WBOY
Release: 2023-04-17 17:52:06
forward
1653 people have browsed it

1. The expression of IFNULL is as follows:

IFNULL(expr1,expr2)

Function description: If expr1 is null, the function returns expr2, otherwise it will Return expr1.

Example 1:

SELECT IFNULL(0,'ab');
Copy after login

How to use IFNULL, NULLIF and ISNULL in MySql

The first parameter is 0, not NULL, so the result is 0.

Example 2:

SELECT IFNULL(NULL,'ab');
Copy after login

How to use IFNULL, NULLIF and ISNULL in MySql

The first parameter is NULL, so the result is ab.

2. The expression of NULLIF is as follows:

SELECT NULLIF(expr1,expr2)

Function description: If two If the two parameters are equal, NULL is returned; otherwise, the first parameter is returned.

Example 1:

SELECT NULLIF('a','b');
Copy after login

How to use IFNULL, NULLIF and ISNULL in MySql

The two parameters are not equal, so the result is the first parameter a.

Example 2:

SELECT NULLIF('a','a');
Copy after login

How to use IFNULL, NULLIF and ISNULL in MySql

The two parameters are equal, so the result is NULL.

3. The expression of ISNULL is as follows:

SELECT ISNULL(expr)

Function description: If expr is null, then isnull() The return value is 1, otherwise the return value is 0.

Example 1:

SELECT ISNULL(NULL);
Copy after login

How to use IFNULL, NULLIF and ISNULL in MySql

The parameter is NULL, so the result is 1.

Example 2:

SELECT ISNULL('ab');
Copy after login

How to use IFNULL, NULLIF and ISNULL in MySql

The parameter is not NULL, so the result is 0.

The above is the detailed content of How to use IFNULL, NULLIF and ISNULL in MySql. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!