Home > Database > Mysql Tutorial > body text

What does % in mysql mean?

下次还敢
Release: 2024-04-26 07:18:15
Original
589 people have browsed it

The % wildcard character in MySQL is used for pattern matching in the LIKE operator, representing zero or more characters. It can be used to find all strings that start with or contain a given pattern, and optionally find strings that end with a given pattern. In addition to %, MySQL provides other wildcard characters, including _, [], ^, and $.

What does % in mysql mean?

The % wildcard character in MySQL

The % in MySQL is a wildcard character, representing zero or more characters . It is used in the LIKE operator for pattern matching.

Syntax

<code>LIKE 'pattern%'</code>
Copy after login

Where:

  • pattern is the string pattern to be matched
  • % is a wildcard character, indicating zero or more characters

Usage

You can use the % wildcard character to match the following conditions String:

  • Starts with the given pattern
  • Contains extensions of any length to the given pattern
  • Optionally, appends any Amount of additional characters

Example

For example, the following query will find all names starting with "John":

<code>SELECT * FROM names WHERE name LIKE 'John%'</code>
Copy after login

This will Returns the following results:

<code>John
John Doe
John Smith</code>
Copy after login

Similarly, the following query will find all words ending with "ing":

<code>SELECT * FROM words WHERE word LIKE '%ing'</code>
Copy after login

This will return the following results:

<code>singing
dancing
running</code>
Copy after login

Other Wildcard characters

In addition to %, MySQL also provides the following wildcard characters:

  • _: matches any single character
  • []: Matches characters within the specified range
  • ^: Negative pattern matching
  • $: Matches the end of the string

The above is the detailed content of What does % in mysql mean?. 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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template