Get the App
SLTechnology News&Howtos  ›  Database  › 

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

Shulou Source: shulou.com Published: 2022-06-01 03:17:55 11月01日 Update

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.

Tags: Spaces characters strings queries precision methods types results trails three binary functions reasons that is what to do data text standards proofreading knowledge Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB NVidia vpn OPPO Reno Linux