Mysql (6) String Pattern Matching

Source: Internet
Author: User


Mysql (6) string mode matching links: Mysql (1) mysql Installation http://www.bkjia.com/database/201210/162314.html Mysql (2) Database Operations http://www.bkjia.com/database/201210/162315.html Mysql (3) operations on Data Tables http://www.bkjia.com/database/201210/162316.html Mysql (4) Data Table query operations http://www.bkjia.com/database/201210/162317.html Mysql (5) operation time http://www.bkjia.com/database/201210/162318.html 1. Matching mysq in the standard SQL mode can use "_" to match any single character and "%" to match any number of characters. = Or! =, Use the LIKE or not like comparison operator. Example of www.2cto.com: 1. Find the name starting with "B" in the student table. SELECT * FROM student WHERE name LIKE "B %"; 2. Find the name ending with "B" in the student table. SELECT * FROM student WHERE name LIKE "% B"; 3. Find the name containing "B" in the student table. SELECT * FROM student WHERE name LIKE "% B %"; 4. Find the name exactly five characters in the student table. SELECT * FROM student WHERE name LIKE "_"; (there are spaces to indicate that there are five "_") 2. If regular expressions are used for pattern matching, we need to use another comparison operator, which is REGEXP or not regexp. Some Characters of the extended regular expression: "." matches any single character. "*" Matches zero or multiple characters before it. "X *" matches any number of X characters. Regular Expressions are case-sensitive and can be matched using a character class. [AA] matches lowercase and upper-case. "^" Indicates the beginning and "$" indicates the end. Example of www.2cto.com: 1. Find the name starting with "B" in the student table. SELECT * FROM student WHERE name REGEXP "^ [bB]"; 2. Find the name ending with "B" in the student table. SELECT * FROM student WHERE name REGEXP "[bB] $"; 3. Find the name containing "B" in the student table. SELECT * FROM student WHERE name REGEXP "[bB]"; 4. Find the name exactly five characters in the student table. SELECT * FROM student WHERE name REGEXP "^ _ $"; (there are spaces to indicate that there are 5 "_")

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.