Home > Database > Mysql Tutorial > body text

What does % mean in mysql

下次还敢
Release: 2024-04-26 07:27:14
Original
1124 people have browsed it

The percent sign % in MySQL is a wildcard character that can match any sequence of characters. It can be used for: 1. String matching (such as: LIKE '%string%'); 2. Range query (such as: BETWEEN '%start%' AND '%end%'); 3. Regular expression matching (such as: REGEXP '%.*%'); Note: % matches any character sequence, but cannot match the empty string; it cannot appear at the beginning or end of a wildcard expression; to match an actual percent sign, the escape character \ needs to be used.

What does % mean in mysql

The percent sign (%) in MySQL

The percent sign (%) in MySQL is a Wildcard, used to match any sequence of characters. It can be used in the following scenarios:

1. String matching

In the LIKE clause, % can be used to match any sequence of characters:

<code class="sql">SELECT * FROM table_name WHERE column_name LIKE '%string%';</code>
Copy after login

This will match any record containing the string "string".

2. Range query

In the BETWEEN clause, % can be used to specify the left or right boundary of the range:

<code class="sql">SELECT * FROM table_name WHERE column_name BETWEEN '%start%' AND '%end%';</code>
Copy after login

This will match Records with column_name values ​​between "start" and "end" (including "start" and "end" themselves).

3. Regular expression

In the REGEXP clause, % can be used as a wildcard to match any character:

<code class="sql">SELECT * FROM table_name WHERE column_name REGEXP '%.*%';</code>
Copy after login

This will match the A record of any sequence of characters.

Note:

  • % matches any sequence of characters, but cannot match the empty string.
  • % cannot appear at the beginning or end of a wildcard expression.
  • To match the actual percent sign, you need to use the escape character \, such as \%.

The above is the detailed content of What does % mean in mysql. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!