MySQL正则表达式是否可以匹配一种模式,以忽略搜索字符(例如Chris.Brown)?
让我们首先创建一个表-
mysql> create table DemoTable ( Name varchar(40) ) ;
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable values('John.Smith');
mysql> insert into DemoTable values('Chris Brown');
mysql> insert into DemoTable values('Chris.Brown');
mysql> insert into DemoTable values('David Miller');
mysql> insert into DemoTable values('Chris.Taylor');使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
这将产生以下输出-
+--------------+ | Name | +--------------+ | John.Smith | | Chris Brown | | Chris.Brown | | David Miller | | Chris.Taylor | +--------------+ 5 rows in set (0.00 sec)
以下是忽略搜索中字符的查询-
mysql> select *from DemoTable where replace(Name,'.','')='Chris Brown';
这将产生以下输出-
+-------------+ | Name | +-------------+ | Chris Brown | +-------------+ 1 row in set (0.00 sec)
热门推荐
2 红丝绒戚风蛋糕
3 夹心小甜点
4 南瓜甜点
6 粘米粉蒸蛋糕
7 酸奶华夫饼
9 红柚鸡蛋糕
10 葡萄干蛋糕
11 紫薯蛋糕卷
13 纸杯裱花小蛋糕
14 果酱奶酪蛋糕
15 日式樱花蔓越莓大福
16 草莓蛋糕卷
17 卡仕达长崎杯子蛋糕