转义百分号DB2 SQL [英] Escape percentage sign DB2 SQL
问题描述
我正在尝试选择一行中包含四个百分比符号的数据。如何避免百分号,以便我的LIKE条件有效?
谢谢
使用转义字符子句 @%
从tbl
中选择*
其中fld像'%@ %%'escape'@'
这将在 fld
列中搜索包含%
字符的所有记录。 p>
DB2 / z格式略有不同:
select *
from tbl
其中fld like {escape'@'}'%@ %%'
显然,你需要仔细选择你的转义字符,所以它不会干扰你的字符串的其余部分,但这对静态字符串来说比较容易。动态构建的字符串将需要动态构建的查询,因此不会使用字符串中的字符。
I am trying to select data containing four percentage signs in a row. How can I escape the percentage signs so my LIKE condition works?
Thanks
Use @%
with the escape character clause:
select *
from tbl
where fld like '%@%%' escape '@'
This will search for all records that contain the "%"
character in the fld
column.
DB2/z has a slightly different format:
select *
from tbl
where fld like {escape '@'} '%@%%'
Obviously, you'll need to choose your escape character carefully so it won't interfere with the rest of your string but this is relatively easy for static strings. Dynamically built strings will require dynamically built queries so that it doesn't use a character from the string.
这篇关于转义百分号DB2 SQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!