转义百分号DB2 SQL [英] Escape percentage sign DB2 SQL

查看:304
本文介绍了转义百分号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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆