The DB2 LIKE predicate query statement supports the use of percent signs (%) and underscores (_), but does not support square brackets ([]) (Note: it will treat square brackets as actual values rather than wildcards). When the percent sign (%) and underscore (_) are used as actual values in LIKE query conditions, you need to use escape characters to tell DB2 to treat them as actual values instead of escape characters. However, DB2 does not define escape characters (backslash \ is not an escape character in DB2), so you need to use the ESCAPE keyword to define, LIKE '%!%' ESCAPE '!'.
It is worth noting that the handling of single quotes is a bit different from that of percent signs (%) and underscores (_). For single quotes, only single quotes can be used to escape, for example: LIKE '''A %', this is to match the string starting with the string "'A"
Percent (%) escape:
select * from table where col1 like '%/%%' escape '/'
The meaning of this statement is to find out the records containing the percent sign (%) character in col1. where escape defines the escape character "/"
Underscore (_) escape:
select * from table where col1 like '%!_%' escape '!'
The meaning of this statement is to find out the records containing the underscore (_) character in col1. where escape defines the escape character "!"
Escaping single quotes:
select * from table where col1 like '%''%'
The meaning of this statement is: find records that contain single quote characters in col1