Protect special characters
The following query uses the keyword ESCAPE with LIKE
or MATCHES so you can protect a special character from misinterpretation
as a wildcard symbol.
Figure 1. Query
SELECT * FROM cust_calls
WHERE res_descr LIKE '%!%%' ESCAPE '!';
The ESCAPE keyword designates an escape character (! in
this example) that protects the next character so that it is interpreted
as data and not as a wildcard. In the example, the escape character
causes the middle percent sign (%) to be treated as data. By using
the ESCAPE keyword, you can search for occurrences of a percent sign
(%) in the res_descr column by using the LIKE wildcard percent
sign (%). The query retrieves the following row.
Figure 2. Query result
customer_num 116
call_dtime 1997-12-21 11:24
user_id mannyn
call_code I
call_descr Second complaint from this customer!
Received two cases righthanded outfielder
glove (1 HRO) instead of one case lefties.
res_dtime 1997-12-27 08:19
res_descr Memo to shipping (Ava Brown) to send case
of lefthanded gloves, pick up wrong case;
memo to billing requesting 5% discount to
placate customer due to second offense
and lateness of resolution because of
holiday.