MySQL Regex 匹配忽略搜索中的字符(如 Chris.Brown)的模式?
mysqlmysqli database
首先我们创建一个表 −
mysql> create table DemoTable ( Name varchar(40) ) ; Query OK, 0 rows affected (0.63 sec)
使用 insert 命令在表中插入一些记录 −
mysql> insert into DemoTable values('John.Smith'); Query OK, 1 row affected (0.30 sec) mysql> insert into DemoTable values('Chris Brown'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('Chris.Brown'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('David Miller'); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable values('Chris.Taylor'); Query OK, 1 row affected (0.18 sec)
使用 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)