MySQL转义字符问题

时间:2014-02-20 09:44:00

标签: mysql mysql-5.5

当我试图解决 This Question. 时,我在表格中创建了虚拟记录

create table mytable(data CHAR(30));

INSERT INTO mytable VALUES('d\\one'),('d\\two'),('d\\three');

SELECT * FROM mytable;
+---------+
| data    |
+---------+
| d\one   |
| d\two   |
| d\three |
+---------+
3 rows in set (0.00 sec)

现在,当我选择记录时,我没有得到任何结果,我已经尝试了许多组合,但没有运气。

例如:

SELECT * FROM mytable WHERE data LIKE "d\\%";
Empty set (0.00 sec)


SELECT * FROM mytable WHERE data LIKE 'd\\%';
Empty set (0.00 sec)

2 个答案:

答案 0 :(得分:2)

使用三斜杠:

SELECT * FROM mytable WHERE data LIKE "d\\\%"

答案 1 :(得分:1)

或者使用INSTR()代替

SELECT * FROM mytable WHERE instr(data, 'd\\') = 1