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

IFN ENULL () and coalesce () functions in mysql

The isnull() function in MySQL cannot be used as a substitute for the null value!

As follows:

First, there is a table named business:

SELECT ISNULL(business_name,'no business_name') AS bus_isnull FROM business WHERE id=2

If you run it directly, it will report an error:

Error code: 1582

Incorrect parameter count in the call to native function'isnull'

So, the isnull() function will not work in mysql.You can use ifnull() and coalesce() instead.As follows:

Use the ifnull() function:

SELECT IFNULL(business_name,'no business_name') AS bus_ifnull FROM business WHERE id=2

Run result:

When the query value is not null:

SELECT IFNULL(business_name,'no business_name') AS bus_ifnull FROM business WHERE id=1

The results are as follows:

Use the coalesce() function:

SELECT COALESCE(business_name,'no business_name') AS bus_coalesce FROM business WHERE id=2

The results are as follows:

When the query value is not null:

SELECT COALESCE(business_name,'no business_name') AS bus_coalesce FROM business WHERE id=1

Among them: coalesce() can also return the first non-null value.As follows:

SELECT COALESCE(business_name,district_id,id) AS bus_coalesce FROM business WHERE id=2

Then, how to use isnull() in mysql Woolen cloth? The answer is to use after where.As follows:

SELECT * FROM business WHERE ISNULL(business_name)

The results are as follows:

Similarly, is null and is not null are also used after where.

SELECT * FROM business WHERE business_name IS NULL

The results are as follows:

SELECT * FROM business WHERE business_name IS NOT NULL

Summary

The above is the entire content of this article.I hope that the content of this article will be helpful to your study or work.If you have any questions, you can leave a message and exchange.Thank you for your support.

Tags

Technical otaku

Sought technology together

Related Topic

1 Comments

author

buy lipitor 10mg & lt;a href="https://lipiws.top/"& gt;atorvastatin for sale online& lt;/a& gt; atorvastatin 20mg tablet

Iczlvc

2024-03-09

Leave a Reply

+