IBM Content Manager, Version 8.5      Supports:  Oracle, DB2, C++, Java

Using escape sequences with the LIKE operator

Escape sequences might not always be necessary with the LIKE operator, but usually they are.

Double quotation mark “

Precede your double quotation mark with another double quotation mark.
//Journal_Article[@Title LIKE “Analysis of ““The Time Machine”” %”]

Because the title of the article contains the name of the book in double quotation marks, “The Time Machine”, these internal double quotation marks must be escaped.

Single quotation mark (apostrophe) '

You do not need to escape in this case. /Book[@Title LIKE “Uncle Tom's Cabin”]

Wildcards (“%”, “_”)

The percent sign % is a wildcard character that is used to represent any number of arbitrary characters in a string that is used with the LIKE operator. The underscore _ is a wildcard character that is used to represent a single arbitrary character. If you want these wildcard characters to be treated as regular characters, you must take the following actions:
  1. Precede the wildcard character with an escape character.
  2. Add an ESCAPE clause with the escape character after the LIKE phrase.
Example A
/Book[@Title LIKE “Plato%s%S_mposium”]

This example shows how wildcards % and _ are used to find a book in which the spelling of the title is uncertain.

Example B
//Journal_Article[@Title LIKE “Usage of underscore !_ in query” ESCAPE “!”]

Because the search string in this example contains the underscore _ as a regular character (not a wildcard), you can escape the underscore with an exclamation point character !. Any single character can be used as an escape character.

Example C
//Journal_Article[@Title LIKE “_sage of underscore \_ in%” ESCAPE “\”]

In this query, wildcard characters are used as both regular characters (_ escaped by \) and as wildcards (_ ) to catch both uppercase and lowercase versions of the word “Usage”, as well as % to catch multiple endings of the string.

Example D
//Journal_Article[@Title LIKE “Usage of underscore !_ on Yahoo!!” ESCAPE “!”]

You can also use an escape character as a regular character. To do so, precede the escape character with itself, as in the example to search for “Yahoo!”.



Feedback

Last updated: December 2013
dcmaq021.htm

© Copyright IBM Corporation 2013.