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

Recommend

How to Rename Multiple Files at Once in Linux

Preface In our daily work, we often need to renam...

js uses FileReader to read local files or blobs

Table of contents FileReader reads local files or...

Implementation of MySQL index-based stress testing

1. Simulate database data 1-1 Create database and...

Implementation of deploying war package project using Docker

To deploy war with Docker, you must use a contain...

Use of Linux ls command

1. Introduction The ls command is used to display...

View the dependent libraries of so or executable programs under linux

View the dependent libraries of so or executable ...

WePY cloud development practice in Linux command query applet

Hello everyone, today I will share with you the W...

Vue imports Echarts to realize line scatter chart

This article shares the specific code of Vue impo...

Detailed explanation of the process of modifying Nginx files in centos7 docker

1. Install nginx in docker: It is very simple to ...

HTML Code Writing Guide

Common Convention Tags Self-closing tags, no need...

How to control the startup order of docker compose services

summary Docker-compose can easily combine multipl...