MySQL process control IF(), IFNULL(), NULLIF(), ISNULL() functions

MySQL process control IF(), IFNULL(), NULLIF(), ISNULL() functions

In MySQL, you can use IF(), IFNULL(), NULLIF(), and ISNULL() functions to control the process.

1. Use of IF() function

IF(expr1,expr2,expr3) returns the value of expr2 if expr1 is true, and returns the value of expr3 if expr1 is false.

SELECT IF(TRUE,'A','B'); -- Output: A
SELECT IF(FALSE,'A','B'); -- Output: B

2. Use of IFNULL() function

IFNULL(expr1,expr2) returns the value of expr2 if the value of expr1 is null, and returns the value of expr1 if the value of expr1 is not null.

SELECT IFNULL(NULL,'B'); -- Output: B
SELECT IFNULL('HELLO','B'); -- Output: HELLO

3. Use of NULLIF() function

NULLIF(expr1,expr2) , if expr1=expr2, then the return value is null, otherwise the return value is the value of expr1.

SELECT NULLIF('A','A'); -- Output: null
SELECT NULLIF('A','B'); -- Output: A

4. Use of ISNULL() function

ISNULL(expr) returns 1 if the value of expr is null, and returns 0 if the value of expr1 is not null.

SELECT ISNULL(NULL); -- Output: 1
SELECT ISNULL('HELLO'); -- Output: 0

The above is the introduction of the use of MySQL process control IF(), IFNULL(), NULLIF(), and ISNULL() functions. I hope it will be helpful to you. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!

You may also be interested in:
  • This article takes you to explore NULL in MySQL
  • MySQL series of experience summary and analysis tutorials on NUll values
  • mysql IS NULL using index case explanation
  • MySql sharing of null function usage
  • Storing NULL values ​​on disk in MySQL

<<:  Introduction to scheduled tasks in Linux system

>>:  7 Ways to Write a Vue v-for Loop

Recommend

How to implement on-demand import and global import in element-plus

Table of contents Import on demand: Global Import...

Solve the problem of HTML automatic formatting after saving in vscode

The version of vsCode has been updated in recent ...

How to use axios to make network requests in React Native

In front-end development, there are many ways to ...

Solution to MySQL remote connection failure

I have encountered the problem that MySQL can con...

A quick guide to MySQL indexes

The establishment of MySQL index is very importan...

Detailed configuration of wireless network card under Ubuntu Server

1. Insert the wireless network card and use the c...

jquery+springboot realizes file upload function

This article example shares the specific code of ...

Detailed explanation of the usage and difference between nohup and & in Linux

Example: We use the Python code loop_hello.py as ...

Summary of JavaScript Timer Types

Table of contents 1.setInterval() 2.setTimeout() ...

Generate OpenSSL certificates in Linux environment

1. Environment: CentOS7, Openssl1.1.1k. 2. Concep...

Three examples of blur background effects using CSS3

Let’s not start with the introduction and get str...

Detailed instructions for installing mysql5.7 database under centos7.2

The mysql on the server is installed with version...

Nginx signal control

Introduction to Nginx Nginx is a high-performance...