MySQL Escape Character Issue

青春壹個敷衍的年華 提交于 2019-12-11 05:44:29

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!