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

How does MySQL use the ESCAPE keyword

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

Share

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

This article mainly introduces MySQL how to use the ESCAPE keyword, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.

MySQL escape

Escape represents the original semantics of the escape character, and the purpose of an escape character is to start a character sequence, so that the character sequence at the beginning of the escape character has a different semantics from that when the character sequence appears alone.

In MySQL, escape characters start with "\", and escape characters commonly used in programming are valid in MySQL, so I won't repeat and discuss them here. Here, the function of the ESCAPE keyword is explained mainly through "%" and "_".

%: matches any number of characters.

_: matches a single character.

If we want to match "%" or "_", we must escape using "\", as follows:

# query users with clear words in their names > SELECT * FROM user WHERE name LIKE CONCAT ("%", "Ming", "%") # query users with% characters in their names > SELECT * FROM user WHERE name LIKE CONCAT ("%", "\%", "%") ESCAPE usage

The main function of the ESCAPE keyword is to specify a character to replace the function of "\".

# query users whose names have the character "%" > SELECT * FROM user WHERE name LIKE CONCAT ("%", "$%", "%") ESCAPE "$" # query users with the character "_" > SELECT * FROM user WHERE name LIKE CONCAT ("%", "a _", "%") ESCAPE "a"

It is important to note that all characters referred to by ESCAPE will replace the function of "\" in the query condition.

# suppose there are two users with names of% an and% _ > SELECT * FROM user WHERE name LIKE "a% _" ESCAPE "a" #% a% _ > SELECT * FROM user WHERE name LIKE "a% a" ESCAPE "a" #% a > SELECT * FROM user WHERE name LIKE "a% a _" ESCAPE "a" #% _ Thank you for reading this article carefully I hope the article "how to use ESCAPE keywords in MySQL" shared by the editor will be helpful to you. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you 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