Detailed use cases of MySql escape

Detailed use cases of MySql escape

MySQL escape

Escape means the original semantics of the escape character. The purpose of an escape character is to start a character sequence so that the character sequence starting with the escape character has different semantics than when the character sequence appears alone.

In the SQL LIKE statement, for example

select * from user where username like '%nihao%',select * from user where username like '_nihao',

Among them, % is used as a wildcard to match multiple characters, and _ is used as a wildcard to match only one character.

If you really want to search for usernames that contain % _ , you need to stop using them as wildcards.

Escape % _ in like, take _ as an example,

Before escaping: select * from user where username like '_nihao',

After escaping: select * from user where username like '/_nihao' escape '/', which means that the _ after / is not used as a wildcard

#Case 3: Query the employee names whose second character is _

SELECT
    last_name
FROM
    employees
WHERE
    last_name LIKE '_$_%' ESCAPE '$';

This is the end of this article about the use of MYSQL escape. For more information on the use of MYSQL escape, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Detailed explanation of how to query fields containing '%' in MySQL like (ESCAPE usage)
  • Detailed explanation of the usage of the ESCAPE keyword in MySQL
  • Analysis of mysql_escape_string() Function Usage

<<:  Mini Program to implement Token generation and verification

>>:  Detailed explanation of the practical use of HTML table layout

Blog    

Recommend

Detailed explanation of mysql record time-consuming sql example

mysql records time-consuming sql MySQL can record...

Mysql join table and id auto-increment example analysis

How to write join If you use left join, is the ta...

An article to understand the execution process of MySQL query statements

Preface We need to retrieve certain data that mee...

CSS polar coordinates example code

Preface The project has requirements for charts, ...

Detailed tutorial on how to install mysql8.0 using Linux yum command

1. Do a good job of cleaning before installation ...

How to optimize a website to increase access speed update

Recently, the company has begun to evaluate all s...

CSS layout tutorial: How to achieve vertical centering

Preface I have been summarizing my front-end know...

Complete steps for Docker to pull images

1. Docker pull pulls the image When using $ docke...

Prototype and prototype chain prototype and proto details

Table of contents 1. Prototype 2. Prototype chain...

CSS achieves footer "bottom absorption" effect

We often encounter this problem: how to use CSS t...

Select web page drop-down list and div layer covering problem

Questions about select elements in HTML have been...

Practical record of handling MySQL automatic shutdown problems

I recently helped someone with a project and the ...