问题
While I was trying to solve This Question. I created the dummy records in a table
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)
Now when i am selecting records, I am getting no result, I have tried many combination with like but no luck.
Ex :
SELECT * FROM mytable WHERE data LIKE "d\\%";
Empty set (0.00 sec)
SELECT * FROM mytable WHERE data LIKE 'd\\%';
Empty set (0.00 sec)
回答1:
Use triple slash:
SELECT * FROM mytable WHERE data LIKE "d\\\%"
回答2:
Or use INSTR() instead
SELECT * FROM mytable WHERE instr(data, 'd\\') = 1
来源:https://stackoverflow.com/questions/21903887/mysql-escape-character-issue