MySQL is not sensitive to space after the query processing of the MySQL database

Source: Internet
Author: User

MySQL is not sensitive to trailing spaces

73530589

Conclusion: It is recommended to trim the string in the query condition, preferably trim when the data is in storage.

Example1:
The field values in the table do not have spaces, where the query condition is with or without spaces.
Example: key= ' Test '
Query condition a:where key= ' test ', the query result is OK
Query condition b:where key= ' test ', query result is empty
Query condition c:where key= ' test ', the query result is OK
Conclusion: The Where query condition is sensitive to the space before the character, and the space after the character is ignored.

Example2: The field value in the table is preceded by a space, where query condition with or without spaces
Example: key= ' Test ' (4 spaces in front of test)
Query condition a:where key= ' test ', the query result is empty.
Query condition b:where key= ' test ' (4 spaces in front of test), query result OK.
Query condition c:where key= ' test ', the query result is empty.
Conclusion: If the value of the field in the table is preceded by a space, the query criteria must match exactly the preceding space.

Example3: Field values in the table are followed by spaces, where query conditions with or without spaces
Example: key= ' Test ' (4 spaces behind test)
Query condition a:where key= ' test ', query result OK
Query condition b:where key= ' test ' (4 spaces after test), query result OK
The query condition c:where key= ' test ' (with 4 spaces in front of test) and the query result is empty.
Conclusion: If the value of the field in the table is followed by a space, the query condition is the same as example1.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced. 73530589

MySQL is not sensitive to space after the query processing of the MySQL database

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.