Preface We already know that MySQL uses the SQL SELECT command and the WHERE clause to read data from a table, but when the query condition field provided is NULL, the command may not work properly. To handle this situation, MySQL provides three major operators:
Conditional comparison operations on NULL are special. You cannot use = NULL or != NULL to look for NULL values in a column. In MySQL, a comparison of a NULL value with any other value (even NULL) always returns false, that is, NULL = NULL returns false. MySQL handles NULL using the IS NULL and IS NOT NULL operators. I'm currently migrating a project from Oracle to MySQL. I encountered some Oracle functions that MySQL doesn't have, so I had to customize the functions or find a way to replace the functions for the transformation. When Oracle sorts data, it can sometimes use nulls first or nulls last to put null values first or last. Oracle method: Null values are sorted first select * from A order by a desc null first Null values are sorted last select * from A order by a desc null last However, if you migrate to MySQL, MySQL does not provide a similar function, so how can you implement it? Here is the solution: Null values are sorted last, using MySQL's IF and ISNULL functions. If it is empty, it returns 1, otherwise it returns 0 select * from A order by IF(ISNULL(a),1,0),a desc Null values are sorted first, using MySQL's IF and ISNULL functions. If it is empty, it returns 1, otherwise it returns 0 select * from A order by IF(ISNULL(a),0,1),a desc If Oracle and MySQL versions are needed in mybatis, you can either pass a data table version identifier dbType from the background, or directly use the _databaseId method of mybatis. <if test="dbType=='oracle'"> order by c.create_date desc nulls last </if> <if test="dbType=='mysql'"> order by IF(ISNULL(c.create_date),1,0), c.create_date desc </if> Summarize The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. If you have any questions, you can leave a message to communicate. Thank you for your support for 123WORDPRESS.COM. You may also be interested in:
|
<<: VMware 15.5 version installation Windows_Server_2008_R2 system tutorial diagram
>>: Detailed explanation of the usage of setUp and reactive functions in vue3
I have encountered a problem. When testing the ed...
Batch comments in SQL Server Batch Annotation Ctr...
1. System Configuration 1. Turn off sudo password...
The docker exec command can execute commands in a...
This article introduces how to configure Nginx to...
In front-end development, we are in direct contac...
This article shares with you the graphic tutorial...
Table of contents 1. Map accepts any type of key ...
Table of contents Defining the HTML structure Inp...
Rendering Code - Take the blue and yellow rings a...
Table of contents Workaround Why can't I moni...
1. <body background=image file name bgcolor=co...
Table of contents 1. Overview 2. Download the Ngi...
I designed and customized a navigation bar with a...
1. Flash plug-in package download address: https:...