我正在尝试查询我们的 MSSQL 数据库,但当那里明显有数据时我却没有得到任何数据。
首先我查询
SELECT id, instruction_link FROM work_instructions WHERE instruction_link LIKE "%\\\\cots-sbs%";
返回 100 多行。 http://tinypic.com/r/ief8td/8 (抱歉,无法发布实际图片,没有足够的代表:(
但是如果我查询
SELECT id, instruction_link FROM work_instructions WHERE instruction_link LIKE "%\\\\cots-sbs\\%";
http://tinypic.com/r/33ksw3q/8
第二个查询没有得到任何结果。我不知道我在这里做错了什么。看起来很简单,但我无法理解它..
提前致谢。
最佳答案
如 LIKE
下所述:
Note
Because MySQL uses C escape syntax in strings (for example, “
\n
” to represent a newline character), you must double any “\
” that you use inLIKE
strings. For example, to search for “\n
”, specify it as “\\n
”. To search for “\
”, specify it as “\\\\
”; this is because the backslashes are stripped once by the parser and again when the pattern match is made, leaving a single backslash to be matched against.
\\%
被解析为包含文字反斜杠后跟百分号字符的字符串,然后将其解释为包含以下内容的模式只是一个字面上的百分号。
关于Mysql 查询不返回带有转义\的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22992620/