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

Analysis of the process of building a cluster environment with Apache and Tomcat

In fact, it is not difficult to build an Apache c...

WeChat applet implements SMS login in action

Table of contents 1. Interface effect preview 2.u...

React+ts realizes secondary linkage effect

This article shares the specific code of React+ts...

Practical MySQL + PostgreSQL batch insert update insertOrUpdate

Table of contents 1. Baidu Encyclopedia 1. MySQL ...

How to remove spaces or specified characters in a string in Shell

There are many methods on the Internet that, alth...

How to deploy Node.js with Docker

Preface Node will be used as the middle layer in ...

React's method of realizing secondary linkage

This article shares the specific code of React to...

react+antd.3x implements ip input box

This article shares the specific code of react+an...

How to display web pages properly in various resolutions and browsers

The key codes are as follows: Copy code The code i...

Example operation MySQL short link

How to set up a MySQL short link 1. Check the mys...

Summary of Linux file directory management commands

touch Command It has two functions: one is to upd...

Implementation of Node connection to MySQL query transaction processing

Table of contents Enter the topic mysql add, dele...