Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the difference between NULL and MySQL empty strings

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article focuses on "what is the difference between NULL and MySQL empty strings". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "what's the difference between NULL and MySQL empty strings?"

The following statements are completely different: MySQL > INSERTINTOmy_table (phone) VALUES (NULL)

Mysql > INSERTINTOmy_table (phone) VALUES ('')

Both statements insert values into the phone column, but the first statement inserts a null value and the second statement inserts an empty string. The meaning of the first case can be interpreted as "the phone number is unknown", while the meaning of the second case can be interpreted as "the person does not have a phone number and therefore does not have a phone number".

For NULL processing, you can use the ISNULL and ISNOTNULL operators and the IFNULL () function.

In SQL, the comparison of a null value to any other value, even if it is NULL, is never "true". Expressions that contain NULL always export null values, unless otherwise specified in the documentation about the operator and in the function of the expression. All columns in the following example return NULL:mysql > SELECTNULL,1+NULL,CONCAT ('Invisible',NULL)

If you plan to search for columns with a column value of NULL, you cannot use expr=NULL tests. The following statement returns no rows because expr=NULL is never "true" for any expression: mysql > SELECT*FROMmy_tableWHEREphone=NULL

To find a null value, you must use an ISNULL test. In the following statement, the way to find NULL phone numbers and empty phone numbers is introduced: mysql > SELECT*FROMmy_tableWHEREphoneISNULL

Mysql > SELECT*FROMmy_tableWHEREphone=''

What are the differences between NULL and MySQL empty strings

More information and examples:

If you are using a MyISAM, InnoDB, BDB, or MEMORY storage engine, you can add an index to a column that may have a null value. If not, the index column NOTNULL must be declared, and NULL cannot be inserted into the column.

When reading data with LOADDATAINFILE, empty or missing columns are updated with''. If you want to have a null value in the column, you should use\ N in the data file. In some cases, the literal word "NULL" can also be used.

When using DISTINCT, GROUPBY, or ORDERBY, all null values are considered equal.

When using ORDERBY, null values are displayed first, and last if DESC is specified in descending order.

Null values are ignored for aggregate (cumulative) functions such as COUNT (), MIN (), and SUM (). The exception to this is COUNT (*), which counts rows instead of individual column values. For example, the following statement produces two counts. First count the number of rows in the table, and then count the number of non-null values in the age column: mysql > SELECTCOUNT (*), COUNT (age) FROMperson

For some column types, MySQL does special treatment for null values. If NULL is inserted into the TIMESTAMP column, the current date and time are inserted. If NULL is inserted into an integer column with the AUTO_INCREMENT attribute, the next number in the sequence is inserted.

At this point, I believe you have a deeper understanding of "what's the difference between NULL and MySQL empty strings". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report