DB2 LIKE escape-expression

来源:互联网 发布:linux下snmpwalk使用 编辑:程序博客网 时间:2024/06/07 03:11

Use @% with the escape character clause:

select *from tblwhere 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 tblwhere 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.


SELECT DISTINCT    COL2,     COL7,COL6FROM    TEST.IMPORTDATA1    WHERE         IMPORTDATA1.COL6 like '%@_10'  escape '@' 


SELECT DISTINCT    COL2,     COL7,COL6FROM    TEST.IMPORTDATA1    WHERE      IMPORTDATA1.COL6 like '%__10'  escape '_' 



参考如下:

Use @% with the escape character clause:

select *from tblwhere 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 tblwhere 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.


原创粉丝点击