Mysql Fuzzy match and escape character

Source: Internet
Author: User

First create a test table:

Insert  into Test (TT) Values ('\\\\172.18.28.153');

Now I want to use fuzzy matching to find out the string that starts with "\\172".

Need to use like because "\" is an escape character, so you need to use 4 "\". The statements are as follows:

SELECT *  from where  like ' \\\\172% ' ;

The result is that I can't get the data I want, which is supposed to be "\\172%" when the string is escaped and should get the result.

After many different attempts, the final successful statement is as follows:

SELECT * FROM test where TT like ' \\\\\\\\172% ';

The reasons for analysis may be as follows:

When MySQL resolves this statement, it escapes first, escaping two "\ \" to a "\"

The condition becomes: TT like ' \\\\172% '. Then, when the like statement is executed, it is escaped again, and the condition becomes: TT like ' \\172% '

The result is returned correctly.

All of this is speculation, because the behavior of the MySQL like statement is not well researched.

Mysql Fuzzy match and escape character

Related Article

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.