如何像“\detail1\detail2\”一样应用 SQL? (逃避'\')?
我有一个表 T1
,其中有一列 details
,数据列具有以下示例数据:
select details from T1;
\this is detail 1\this is detail2\
\this is detail 1\this is detail2\
:this is detail 1:this is detail2:
:this is detail 1:this is detail2:
\this is detail 1\this is detail2\
我只想获取那些由 < 分隔的 details
代码>\。
为此,我编写了以下查询:
select details from T1 where details like '\%\%\';
但它没有按预期响应,因为它采用 \ 作为转义校正器。
所以,它显示了不完整的单个 inverted(') 错误!
那么,该怎么做呢?
I have a table T1
with a column details
, data column has following sample data :
select details from T1;
\this is detail 1\this is detail2\
\this is detail 1\this is detail2\
:this is detail 1:this is detail2:
:this is detail 1:this is detail2:
\this is detail 1\this is detail2\
I want to fetch only those details
which are separated by \
.
For that I wrote the following query :
select details from T1 where details like '\%\%\';
But its not responding as expected, since its taking \ as escape corrector.
So, its showing error of incomplete single inverted(') !
So, how to do this ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
试试这个,你需要在 LIKE 语句中转义反斜杠两次。
http://dev.mysql.com/doc/refman /5.0/en/string-comparison-functions.html
Try this, you need to escape backslashes twice in LIKE statement.
http://dev.mysql.com/doc/refman/5.0/en/string-comparison-functions.html
MySql 有用于反斜杠的转义字符 \\(与类 C 语言相同):
http://dev.mysql.com/doc/refman/5.0/en/string-syntax.html
MySql has escape character \\ for backslash (same as in C-like languages):
http://dev.mysql.com/doc/refman/5.0/en/string-syntax.html
尝试使用 '\\%\\%\\' - 使用反斜杠来转义反斜杠。
Try using '\\%\\%\\' - using a backslash to escape the backslash.