处理 DB2 中的转义序列字符
我想搜索一列并获取值包含 \ 的值。
我尝试从“Values”中选择*,其中“ValueName”如'\'
。但没有返回任何值。
还尝试了 like "\"
和 like'\''%'
等,但没有结果。
I want to search a column and get values where value containts \ .
I tried select * from "Values" where "ValueName" like '\'
. But returns no value.
Also tried like "\"
and like'\''%'
etc. But no results.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
请参阅 LIKE 谓词,特别是有关转义表达式的部分。
你想要的是
给出一个用法的例子:
返回3(所有3行都带有\)。
返回 1(\bar 行)。
See the DB2 Documentation on the LIKE predicate, in particular the parts about escape expressions.
What you want is
To give an example of usage:
returns 3 (all 3 rows with \ in them).
returns 1 (the \bar row).
value 是一个不太好的名称,因为它可能与 value 关键字混淆
values is a not so good name because it may be confused with the values keyword
不要逃避它。您只需要在它周围使用通配符,如下所示:
但是,假设您确实需要转义斜线。这是一个更简单、更直接的答案:
转义表达式允许您指定您想要的任何转义字符。那么为什么要使用您正在寻找的角色,从而要求您转义它呢?请改用任何其他字符。我将使用加号作为示例,但它可以是反斜杠、井号、问号、除您要查找的字符或通配符之一(% 或 _)之外的任何字符。
现在您不必在您的类似模式中添加任何内容。
为了让自己遵守@Michael 所演示的相同证明标准——
每个方法返回相同数量的行:
Don't escape it. You just need wildcards around it like this:
But, suppose you really do need to escape the slash. Here's a simpler, more straightforward answer:
The escape-expression allows you to specify whatever character for escaping that you wish. So why use a character that you're looking for, thus requiring you to escape it? Use any other character instead. I'll use a plus sign as an example, but it could be a backslash, pound-sign, question-mark, anything other than a character you are looking for or one of the wildcard characters (% or _).
Now you don't have to add anything into your like-pattern.
To hold myself to the same standard of proof that @Michael demonstrated --
Which returns the same number of rows for each method: