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)
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C語言程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP