MySQL 查询因标点符号而不匹配?

mysqlmysqli database

使用 MySQL LIKE 运算符进行匹配,即使存在标点符号。让我们首先创建一个表 −

mysql> create table DemoTable
   -> (
   -> Comments varchar(20)
   -> );
Query OK, 0 rows affected (1.10 sec)

使用 insert 命令在表中插入一些记录 −

mysql> insert into DemoTable values('Good,Morning');
Query OK, 1 row affected (0.15 sec)
mysql> insert into DemoTable values('Nice');
Query OK, 1 row affected (0.51 sec)
mysql> insert into DemoTable values('good,bye!');
Query OK, 1 row affected (0.11 sec)

使用 select 语句显示表中的所有记录 −

mysql> select *from DemoTable;

这将产生以下输出 −

+--------------+
|  Comments    |
+--------------+
| Good,Morning |
| Nice         |
| good,bye!    |
+--------------+
3 rows in set (0.00 sec)

以下是即使存在标点符号也要匹配的查询 −

mysql> select *from DemoTable where Comments like '%good%';

这将产生以下输出 −

+--------------+
| Comments     |
+--------------+
| Good,Morning |
| good,bye!    |
+--------------+
2 rows in set (0.00 sec)

相关文章