• notice
  • Congratulations on the launch of the Sought Tech site

The ifnull() function in MySQL judges the null value

We know that in different database engines, there are differences in the implementation and naming of built-in functions.If you frequently switch to use these database engines, it is easy to confuse these functions.

For example, the function for judging the null value is the NVL() function and NVL2() function in Oracle , and the ISNULL() function in SQL Server.These functions include replacing the return value with another when the value is a null value.A value of the second parameter.

But in MySQL , the ISNULL() function is only used to determine the null value, accepting a parameter and returning a Boolean value, and does not provide a second parameter that replaces the return value with another value when the value is null.

SELECT ISNULL('i like yanggb'); // 0
SELECT ISNULL(NULL); // 1

Therefore, MySQL additionally provides an IFNULL() function.

a brief introdction

The IFNULL() function is one of MySQL's built-in control flow functions.It accepts two parameters.The first parameter is the field or value (silly?) to determine the null value, and the second field is when the first parameter is empty.In the case of a value, replace the returned value with another value. If the first parameter is not NULL, the first parameter will be returned; otherwise, the second parameter will be returned. Both parameters can be literal values or expressions.

Function syntax

IFNULL(v1, v2)

Among them, if v1 is not NULL, the IFNULL function returns v1; otherwise, it returns the result of v2.

Simple example

SELECT IFNULL(NULL,'i like yanggb'); // i like yanggb

In the above example, since the first parameter is NULL, the value of the second parameter is returned.

SELECT IFNULL('i like yanggb','i do like yanggb'); // i like yanggb

In the above example, since the first parameter is not NULL, the value of the first parameter is returned.


Tags

Technical otaku

Sought technology together

Related Topic

1 Comments

author

buy lipitor 40mg generic & lt;a href="https://lipiws.top/"& gt;how to get lipitor without a preion& lt;/a& gt; buy atorvastatin without preion

Moteqv

2024-03-07

Leave a Reply

+