Home >Database >Mysql Tutorial >MYSQL的模式查询

MYSQL的模式查询

WBOY
WBOYOriginal
2016-06-07 16:51:011077browse

另外一种是用正则表达式匹配。 如查询所有owner为#39;陈...#39;的pet. select * from pet where owner regexp #39;^陈#39;; 或select *

假设MYSQL有一数据库,它有一个表pet.
+---------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| name | varchar(20) | YES | | NULL | |
| owner | varchar(20) | YES | | NULL | |
| species | varchar(20) | YES | |p NULL | |
| sex | char(1) | YES | | NULL | |
| birth | date | YES | | NULL | |
| death | date | YES | | NULL | |
+---------+-------------+------+-----+---------+-------+

一种是sql的标准匹配。
查询name以b开头的所有记录:
select * from pet where name like 'b%';
这里的'%'类似于windows系统下面的'*',而'_'类似于 windows下面的'?'。

另外一种是用正则表达式匹配。
如查询所有owner为'陈...'的pet.
select * from pet where owner regexp '^陈';
或select * from pet where owner rlike '^陈';
找出pet name正好为4他字符的情况。
select * from where name rlike '^{4}$';
或select * from where name rlike '^....$';
这些和一般的正则表达式的用法是类似的。

linux

Statement:
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