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)

更新於:2019-12-12

99 次瀏覽

啟動你的 職業生涯

完成課程以獲得認證

開始
廣告
© . All rights reserved.