MySQL Learning--mysql must be known 1

Source: Internet
Author: User

?? For example, the following is the Nineth chapter of MySQL must be known to start:

The normal form is used to match a particular character set. MySQL provides preliminary support for the regular form through the WHERE clause.

Keywordregexp is used to denote what is followed as a form of processing.

(.) is a symbol of a regular expression that matches a random character:

Mysql> Select Prod_name, from Products,    where Prod_name regexp '. ORDER by    prod_name;+ --------------+| Prod_name    |+--------------+| JetPack 1000 | | JetPack |+--------------+2 rows in Set (0.14 sec)

| match character:

Represents one of the matches among

Mysql> Select Prod_name, from Products,    where Prod_name REGEXP ' 1000|2000 '    ORDER by Prod_n ame;+--------------+| Prod_name    |+--------------+| JetPack 1000 | | JetPack |+--------------+2 rows in Set (0.00 sec)


[] Match: Matches one of several characters

2 rows in Set (0.00 sec) mysql> Select Prod_name, from Products,    where Prod_name regexp ' [123] Ton ' 
   ->, +-------------+| Prod_name   |+-------------+| 1 ton Anvil | | 2 ton anvil |+-------------+2 rows in Set (0.00 sec)
Mysql> Select Prod_name from Products where prod_name regexp ' [1-5] Ton '; +--------------+| Prod_name    |+--------------+|. 5 Ton Anvil | | 1 ton Anvil  | | 2 Ton anvil  |+--------------+3 rows in set (0.02 s Ec


(^) Negative match:

Mysql> Select Prod_name from Products where prod_name regexp ' [^1-3] Ton '; +--------------+| Prod_name    |+--------------+|. 5 ton Anvil |+--------------+1 row in Set (0.00 sec)


To match Special characters, you must use \ \ as the leading.

Mysql> Select Prod_name from Products where prod_name regexp ' \ \. '; +--------------+| Prod_name    |+--------------+|. 5 ton Anvil |+--------------+1 row in Set (0.00 sec)


Match character class:

Mysql> Select Prod_name from Products where prod_name REGEXP ' \ \ ([0-9] sticks?\\) ' ORDER by prod_name;+---------------- +| Prod_name      |+----------------+| TNT (1 stick)  | | TNT (5 sticks) |+----------------+2 rows in Set (0.05 sec) mysql> Select Prod_name from Products where Prod_name REGEXP ' [[:d igit:]]{4} ' ORDER by prod_name;+--------------+| Prod_name    |+--------------+| JetPack 1000 | | JetPack |+--------------+2 rows in Set (0.00 sec)


How to use Locators:

Mysql> Select Prod_name, from Products,    where Prod_name REGEXP ' ^[0-9\\.] '    ORDER BY prod_name;+--------------+| Prod_name    |+--------------+|. 5 Ton Anvil | | 1 ton Anvil  | | 2 Ton anvil  |+--------------+3 rows in Set (0.00 s Ec

These are the methods used by MySQL in the form of expressions.
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.