MySQL查询由于标点符号不匹配?
使用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)
广告