2011-12-18 42 views
1
mysql> select 'ab' like 'a_%'; 
+-----------------+ 
| 'ab' like 'a_%' | 
+-----------------+ 
|    1 | 
+-----------------+ 
1 row in set (0.00 sec) 

mysql> select 'ab' like 'a\_%'; 
+------------------+ 
| 'ab' like 'a\_%' | 
+------------------+ 
|    0 | 
+------------------+ 
1 row in set (0.00 sec) 

mysql> select 'a_b' like 'a\_%'; 
+-------------------+ 
| 'a_b' like 'a\_%' | 
+-------------------+ 
|     1 | 
+-------------------+ 
1 row in set (0.00 sec) 

爲什麼我需要逃脫_爲什麼在MySQL中_特別?

+3

一個谷歌搜索「的MySQL像下劃線」會找到你想要的,你的信息。 (甚至只是「mysql下劃線」。) –

回答

9

因爲_%都是LIKE的特殊字符。

_匹配一個字符,%任意數量的字符。

0
"_" means underscore. I think "_" used for hiding any character under it. It is special because we can place character for it. 

你可以得到更多的從這些鏈接:

link1

link2

link3

link4

link5

link6