我有這個表:帶括號的邊界Mysql的比賽的話
mysql> SELECT * FROM test;
+----+---------------+
| id | duma |
+----+---------------+
| 1 | bbb ccc ddd |
| 2 | bbb (ccc) ddd |
| 3 | ccc ddd eee |
| 4 | (ccc) ddd eee |
| 5 | aaa bbb ccc |
| 6 | aaa bbb (ccc) |
| 7 | bbb(ccc)ddd |
| 8 | (ccc)dddeee |
| 9 | aaabbb(ccc) |
+----+---------------+
9 rows in set (0.00 sec)
我想匹配「(CCC)」字符串作爲詞而已,所以我想看看行#2,#4結果中#6。我試圖theese:
mysql> SELECT * FROM test WHERE duma REGEXP '[[:<:]](ccc)[[:>:]]';
+----+---------------+
| id | duma |
+----+---------------+
| 1 | bbb ccc ddd |
| 2 | bbb (ccc) ddd |
| 3 | ccc ddd eee |
| 4 | (ccc) ddd eee |
| 5 | aaa bbb ccc |
| 6 | aaa bbb (ccc) |
| 7 | bbb(ccc)ddd |
| 8 | (ccc)dddeee |
| 9 | aaabbb(ccc) |
+----+---------------+
9 rows in set (0.00 sec)
好吧,括號是模式字符,我試圖逃避它:
mysql> SELECT * FROM test WHERE duma REGEXP '[[:<:]]\\(ccc\\)[[:>:]]';
Empty set (0.00 sec)
mysql> SELECT * FROM test WHERE duma REGEXP '[[:<:]][(]ccc[)][[:>:]]';
Empty set (0.00 sec)
有沒有什麼解決辦法嗎?
你必須使用正則表達式嗎?爲什麼不''SELECT * FROM test WHERE duma LIKE'%(ccc)%''? – Fredster
對不起,我寫了不好的示例表數據。現在我糾正了它。 –