DB2 10.5 for Linux, UNIX, and Windows

Escaping special characters

Special characters can serve different functions in the query syntax.

To search for a special character that has a special function in the query syntax, you must escape the special character by adding a backslash before it, for example:

Not escaping such special characters can result in syntax errors.

Table 1. Special characters that must be escaped to be searched
Special character Notes on behavior when not escaped
Ampersand (&)  
Asterisk (*) Used as a wildcard character.
At sign (@) A syntax error is generated when an at sign is the first character of a query. In xmlxp expressions, the at sign is used to refer to an attribute.
Brackets [ ] Used in xmlxp expressions to search the contents of elements and attributes.
Braces { } Generates a syntax error.
Backslash (\)  
Caret (^) Used for weighting (boosting) terms.
Colon (:) Used to search in the contents of fields.
Equal sign (=) Generates a syntax error.
Exclamation point (!) A syntax error is returned when an exclamation point is the first character of a query.
Forward slash (/) In xmlxp expressions, a forward slash is used as an element path separator.
Greater than symbol (>) Less than symbol (<) Used in xmlxp expressions to compare the value of an attribute. Otherwise, these characters generate syntax errors.
Minus sign (-) When a minus sign is the first character of a term, only documents that do not contain the term are returned.
Parentheses ( ) Used for grouping.
Percent sign (%) Specifies that a search term is optional.
Plus sign (+)  
Question mark (?) Handled as a wildcard character.
Semicolon (;)  
Single quotation mark (') Single quotation marks are used to contain xmlxp expressions.
Tilde (~) Handled as proximity and fuzzy search operators.
Vertical bar (|)  

Escaping special characters that do not serve a special function in the query syntax is optional. The following table shows some examples of special characters that do not require escaping.

Table 2. Examples of special characters that do not require escaping
Special character Notes
Comma (,)  
Dollar sign ($)  
Period (.) In xmlxp expressions, a period is used to search the content of elements.
Pound sign (#)  
Underscore (_)