Was this helpful?
The LIKE Operator and Pattern Matching
All the comparison operators used in 4GL require you to compare values for exact matching. 4GL has a pattern‑matching capability that allows you to compare two strings and see whether they resemble each other in specified ways.
To do this, specify a pattern to determine what the compared string must look like, along with the LIKE pattern-matching operation. If the string you specify matches the pattern in the pattern string, the comparison evaluates to True. Use the LIKE operation in if and while statements. The syntax for the LIKE operation is as follows:
variable [NOT] LIKE pattern
The parameter variable refers to a character string column, and pattern is a character string literal or character string variable.
Pattern strings can include the following special characters:
A question mark (?) is a "wildcard" that matches any single character. For example, "Xa," "aa" and "/a" are all text strings that match the pattern string "?a."
An asterisk (*) is a "wildcard" that matches any string of characters, regardless of length. For example, the pattern string "Fred*" matches the strings "Fred," "Frederick," and "Fred S. Smith, Ph.D."
Square brackets [ ] denote the beginning and end of a list of characters. Place brackets around the character in the string to be matched. For example, the pattern string "?[BC]C*" matches a string that has any character in the first position, a "B" or "C" in the second position, and a capital "C" in the third position.
The strings "ABC," "ACC," and "FCC Fairness Doctrine" are all valid instances of the pattern string "?[BC]C*" while "FDC Yellow #42" and "Access" are not.
Use the LIKE operator as any other comparison operator is used. For example, to test whether a text value ends in the letter "e," issue the following statement:
if name like "*e" then
 message "Found a name ending in e";
endif;
The following example tests the value of variable "emp_name" against the pattern "Fred*Smith" to see if it starts with "Fred" and ends with Smith.
if emp_name like "Fred*Smith" then
 message "Found a guy matching the pattern"
endif;
In QUEL, the pattern matching characters are always active in comparison clauses. The special meaning can be disabled by preceding it with a backslash (\). Note, however, that the pattern-matching characters operate like ordinary characters in assignment statements, as in the following:
jtitle := "**accountant**"
To retrieve the value requires the syntax shown in the following code fragment:
j.jtitle = "\*\*accountant\*\*"
Last modified date: 04/03/2024