[MySQL] In the query, the NULL value is converted to an empty string

series of articles

C# underlying library-MySQLBuilder script construction class (select, insert, update, in, automatic generation of SQL with conditions)
link to this article: https://blog.csdn.net/youcheng_ge/article/details/129179216

C# underlying library – MySQL database operation auxiliary class (recommended reading)
link to this article: https://blog.csdn.net/youcheng_ge/article/details/126886379

C# underlying library – the use of SQLite (small, local database)
link to this article: https://blog.csdn.net/youcheng_ge/article/details/123666958

[Improve programming efficiency] Import Excel data into the database in batches
Link to this article: https://blog.csdn.net/youcheng_ge/article/details/126427323

[Oracle] The database server restricts ip access to
this article link: https://blog.csdn.net/youcheng_ge/article/details/122220930

[Oracle] Excel Import Data Tutorial
Link to this article: https://blog.csdn.net/youcheng_ge/article/details/118722756

[Oracle] Database Restore Tutorial_Data Pump
Link to this article: https://blog.csdn.net/youcheng_ge/article/details/118054855

[SQL] How to query table fields and identify primary keys
Link to this article: https://blog.csdn.net/youcheng_ge/article/details/110820405

[SQL] Usage of outer apply
Link to this article: https://blog.csdn.net/youcheng_ge/article/details/79903489

[SQL] Multi-table connection duplicate data processing
Link to this article: https://blog.csdn.net/youcheng_ge/article/details/79903619

MySQL installation tutorial (detailed)
link to this article: https://blog.csdn.net/youcheng_ge/article/details/126037520

MySQL uninstall tutorial (detailed)
link to this article: https://blog.csdn.net/youcheng_ge/article/details/129279265

[MySQL] How to add the "total" field for group by classification and summary?
Link to this article: https://blog.csdn.net/youcheng_ge/article/details/128217837

[MySQL] Usage of WITH CHECK OPTION
Link to this article: https://blog.csdn.net/youcheng_ge/article/details/128147196

[MySQL] How to improve efficiency by using stored procedures to insert tens of millions of data?
Link to this article: https://blog.csdn.net/youcheng_ge/article/details/77728189

[MySQL] Realization of row and column transposition of database table
Link to this article: https://blog.csdn.net/youcheng_ge/article/details/77625052


foreword

This column is [Database], which mainly introduces the functions and characteristics of SQL, SQL data definition language (table, view, index, constraint), SQL data manipulation language (data retrieval, data insertion, data deletion, data update), creation and deletion Triggers, SQL Data Control Language (Security and Authorization, Transaction Processing), and Embedded SQL.
If you are interested in this album, keep paying attention. If you have any questions, you can also give feedback in the comment area and private message me.
insert image description here

1. Technical introduction

The syntax format of IFNULL() function is:

IFNULL(expression, alt_value)
Returns the alternate value of the second parameter if the expression expression of the first parameter is NULL.
Parameter description:
expression is required, the value to be tested
alt_value is required, expression is the value returned when the expression is NULL

2. Test cases

2.1 Before conversion

-- 已经入 产品库
SELECT a.公司编号,
a.成品短码,
a.成品编号,
a.成品规格,
a.成品直径,
a.成品长度,
a.成品重量,

b.客户编号,
b.发货计划编号,
b.发货计划备注
FROM dl_mes.成品信息表 a
LEFT JOIN dl_mes.成品销售发货表 b
ON a.成品编号=b.成品编号
WHERE a.仓库编号='03'

insert image description here

2.2 After conversion

Create user information table userinfo

-- 已经入 产品库
SELECT a.公司编号,
a.成品短码,
a.成品编号,
a.成品规格,
a.成品直径,
a.成品长度,
a.成品重量,

IFNULL(b.客户编号,'') AS '客户编号',
IFNULL(b.发货计划编号,'') AS '发货计划编号',
IFNULL(b.发货计划备注,'') AS '发货计划备注'
FROM dl_mes.成品信息表 a
LEFT JOIN dl_mes.成品销售发货表 b
ON a.成品编号=b.成品编号
WHERE a.仓库编号='03'

insert image description here

3. Usage summary

The IFNULL() function is used to judge whether the first expression is NULL. If it is NULL, it returns the value of the second parameter. If it is not NULL, it returns the value of the first parameter.

Guess you like

Origin blog.csdn.net/youcheng_ge/article/details/130381878