Escape percentage sign DB2 SQL

和自甴很熟 提交于 2019-12-10 02:29:13

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/700648/escape-percentage-sign-db2-sql

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!