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

Explain in detail the problem that the string can be matched with spaces at the end of the string in Mysql query conditions.

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

I. Table structure

TABLE person

Idname1 you 2 you (one space) 3 you (two spaces)

II. Query and result

Select * from person where `name` =?

No matter? = "you + several spaces" will retrieve all three results.

Third, the reason

MySQL proofreading rules belong to PADSPACE and trailing spaces are ignored.

It's for varchar char text. The data type of the text class

This is the SQL standardization behavior. There is no need to set and cannot be changed.

Fourth, what if you want to make an accurate query?

Method 1: like

Select * from person where `name` like?

Method 2: BINARY

Select * from person where `name` = BINARY?

BINARY is not a function, but a type conversion operator. It is used to force the string after it to be a binary string, which can be understood as an exact match.

The above are all the relevant knowledge points of this introduction, if you have anything to add, you can contact the editor.

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