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 to understand the escape characters of MySQL

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

Share

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

Today, I will talk to you about how to understand the escaped characters of MySQL, which may not be well understood by many people. in order to make you understand better, the editor has summarized the following for you. I hope you can get something according to this article.

Escape character of MySQL ""

MYSQL recognizes the following escape characters:

An ASCII 0 (NUL) character.

N

A new line character.

T

A locator.

R

A carriage return.

B

A backspace character.

'

A single quote ("'") character.

"

A double quote ("") character.

A backslash (").

%

A "%" character. It is used to search for a text instance of "%" in the body, otherwise "%" will be interpreted as a wildcard.

_

A "_" character. It is used to search for a text instance of "_" in the body, otherwise "_" will be interpreted as a wildcard.

Note that if you use "%" or "% _" in some text environments, these will return the strings "%" and "_" instead of "%" and "_".

★★

There are several ways to include quotation marks in a string:

1. Those that must be escaped:

A string is referenced by a single quotation mark "'", and the single quote "'" character in the string can be escaped in the "'" way.

A string is referenced in double quotation marks, and the "" character in the string can be escaped in the ""way.

At the same time, you can continue to use an escape character "" to escape.

2. Can not be escaped:

A string is referenced by double quotation marks. The single quotation mark "'" in the string does not require special treatment and does not have to be repeated or escaped.

The same principle

A string is referenced by single quotation marks. The double quotation marks in the string do not require special treatment and do not need to be repeated or escaped.

The select shown below demonstrates how quotation marks and escaping work:

Mysql > SELECT 'hello',' "hello",'"" hello ""', 'hel''lo',' 'hello'

+-+

"hello", "hel'lo", "hello"

+-+

Mysql > SELECT "hello", "'hello'", "' hello''", "hel"lo", "" hello "

+-+

"hello"hello'"hello''" hel "lo"hello"

+-+

Mysql > SELECT "ThisnIsnFournlines"

+-+

"This

Is

Four

Lines coach

+-+

If you want to insert binary data into a BLOB column, the following characters must be represented by an escape sequence:

NUL

ASCII 0 . You should denote it with''(a backslash and an ASCII'0').

ASCII 92, backslash. Denoted by''.

'

ASCII 39, single quotation marks. It's denoted by "'".

"

ASCII 34, double quotation marks. It is indicated by ".

After reading the above, do you have any further understanding of how to understand the escaped characters of MySQL? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

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