mysql in IFNULL () function to determine a null value

We know that in different database engines, built to achieve the function, naming all the differences, if you frequently switch between these database engine, it will be very easy to confuse these functions.

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

However, in MySQL, the ISNULL () function only for determining null, accepts a parameter and returns a Boolean value, does not provide a null value when the return value is replaced by another value of the second parameter.

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

Thus a function is additionally provided MySQL IFNULL ().

basic introduction

The IFNULL () function is a function of one of the control flow built MySQL, which accepts two parameters, the first parameter is determined to be a field or null values ​​(stupid?), The second field is empty when the first parameter is When the value of another value to be replaced is returned. If the first argument is not NULL, the first parameter is returned; otherwise, it returns its second argument. Both parameters can be a literal value or expression.

The syntax of the function

IFNULL(v1, v2)

Which, if v1 is not NULL, the function returns IFNULL v1; otherwise the results v2.

A simple example

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

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

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

In the above example, since the first parameter is not NULL, it returns a value of the first parameter.

 

"You seem lost, her hair longer, and back to make me feel strange, you see things is the last century, and then you began to call my name, I wanted to laugh, as if he had just school, only at the school gate, etc. you just five minutes. "

Guess you like

Origin www.cnblogs.com/yanggb/p/11658548.html