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

Complete steps for using Echarts and sub-packaging in WeChat Mini Program

Preface Although the holiday is over, it shows up...

W3C Tutorial (5): W3C XML Activities

XML is designed to describe, store, transmit and ...

Mysql auto-increment primary key id is not processed in this way

Mysql auto-increment primary key id does not incr...

Front-end vue+express file upload and download example

Create a new server.js yarn init -y yarn add expr...

Solution to the problem of MySQL data delay jump

Today we analyzed another typical problem about d...

CSS achieves the effect of two elements blending (sticky effect)

I remember that a few years ago, there was an int...

Nginx cache configuration example

When developing and debugging a web application, ...

Implementation of Nginx load balancing/SSL configuration

What is load balancing? When a domain name points...

Detailed explanation of the JVM series memory model

Table of contents 1. Memory model and runtime dat...

Some things to note about varchar type in Mysql

Storage rules for varchar In versions below 4.0, ...

5 ways to achieve the diagonal header effect in the table

Everyone must be familiar with table. We often en...

Why is UTF-8 not recommended in MySQL?

I recently encountered a bug where I was trying t...