- Trained on our vast library of engineering resources.
Joe Celko's SQL for Smarties: Advanced SQL Programming, Third Edition

Chapter 12: LIKE Predicate

Overview

The like predicate is a string pattern-matching test with the syntax:

 ::=     [NOT] LIKE         [ESCAPE ] ::=  ::=  ::= 

The expression M NOT LIKE P is equivalent to NOT (M LIKE P), which follows the usual syntax pattern in SQL. Two wildcards are allowed in the string. They are the '%' and '_' characters. The '_' character represents a single arbitrary character; the '%' character represents an arbitrary substring, possibly of length zero. Notice that there is no way to represent zero or one arbitrary character. This is not the case in many text-search languages, and can lead to problems or very complex predicates.

Any other character in the represents that character itself. This means that SQL patterns are case-sensitive, but many vendors allow you to set case sensitivity on or off at the database system level.

The is used in the to specify that the character that follows it is to be interpreted literally rather than as a wildcard. This means that the escape character is followed by the escape character itself, an '_' or a '%'. Old C programmers are used to this convention, where the language defines the escape character as '\', so this is a good choice for SQL programmers, too.

12.1 Tricks with Patterns

The '_' character tests much faster than...

UNLIMITED FREE ACCESS TO THE WORLD'S BEST IDEAS

SUBMIT
Already a GlobalSpec user? Log in.

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.

Customize Your GlobalSpec Experience

Category: Optical Character Recognition Software (OCR)
Finish!
Privacy Policy

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.