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

查看:18
本文介绍了转义百分号 DB2 SQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试选择连续包含四个百分号的数据.如何避开百分号以便我的 LIKE 条件起作用?

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?

谢谢

推荐答案

使用 @% 和转义字符子句:

Use @% with the escape character clause:

select *
from tbl
where fld like '%@%%' escape '@'

这将搜索 fld 列中包含 "%" 字符的所有记录.

This will search for all records that contain the "%" character in the fld column.

DB2/z 的格式略有不同:

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天全站免登陆