为什么_在MySQL中特殊?

时间:2011-12-18 14:02:27

标签: mysql

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)

为什么我需要转义_

2 个答案:

答案 0 :(得分:9)

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

_匹配一个字符,%任意数量的字符。

答案 1 :(得分: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