Home > Daily Programming > Mysql Knowledge > What does % represent in mysql

What does % represent in mysql

下次还敢
Release: 2024-04-27 03:42:14
Original
901 people have browsed it

The percent symbol % in MySQL is a wildcard character used to match any number of characters in a string. It can be placed at the beginning, end, or middle to find strings that contain, begin, or end the specified character pattern. In addition to %, MySQL supports other wildcard characters such as underscore _ and square brackets [set].

What does % represent in mysql

The meaning of % in MySQL

In MySQL, the % symbol represents a wildcard character, which is used in strings Matches any number of characters.

Usage of wildcard characters

% symbol can be placed at the beginning, end, or middle of a string query to match various character patterns:

  • Matches starting with: %keyword matches any string starting with "keyword".
  • End match: keyword% matches any string ending with "keyword".
  • Intermediate matching: %keyword% matches any string containing "keyword".

Example

Here are some examples of MySQL queries using the % wildcard:

  • Find the query containing All user names for "John":

    SELECT username FROM users WHERE username LIKE '%John%';
    Copy after login
  • Find all tables starting with "admin":

    SHOW TABLES LIKE 'admin%';
    Copy after login
  • Find all fields that contain "customer" but end with "cust":

    SELECT column_name FROM information_schema.columns WHERE column_name LIKE '%customer' AND column_name LIKE 'cust%';
    Copy after login

Other wildcards

In addition to %, MySQL also supports other wildcard characters:

  • _: The underscore matches a single character.
  • [set]: Square brackets match any character in the specified character set (for example, [a-z] matches all lowercase letters).

Notes

  • % Wildcard characters may cause query performance degradation, so they should be used with caution.
  • Case Sensitive: MySQL wildcards are case sensitive, which means that %keyword and %KEYWORD will not match the same results.
  • Escape characters: If you need to search for actual % characters in the query, use the escape character \, for example \%keyword.

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

Related labels:
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 Issues
MySQL stops process
From 1970-01-01 08:00:00
0
0
0
Error when installing mysql on linux
From 1970-01-01 08:00:00
0
0
0
phpstudy cannot start mysql?
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template