LIKE

LIKE operator tests whether a character value matches a quoted string:

where mask is a character expression.

LIKE is similar to MATCHES. Their only difference is that they support different wild cards.

If an operand has a null value, the entire string comparison returns NULL.

mask can include the percent (%) and underscore (_) symbols. % can represent any number of characters, and an underscore (_) replaces only one character. If you want to use % or _ as literal characters, you must put a backslash (\) in front of them.

 

The string that LIKE can return includes literals, wild cards and other symbols.

If you use LIKE to compare strings, wild cards used for MATCHES have no special significance but you can use % or _.

This piece of code tests for the string board in the character variable, either alone or in a longer string:

IF string LIKE "%board%"

This piece of code tests whether this string includes an underscore symbol. The backslash (\) is necessary because _ is a wild card with LIKE:

IF string LIKE "%\__%" THEN ...

You can replace the backslash (\) as the literal symbol. If you include an ESCAPE char clause in an expression with LIKE or MATCHES, 4gl interprets the character that follows char as a literal even if that character corresponds to a special symbol of LIKE or MATCHES. A double quotation mark (") cannot be used as a CHAR variable.

For example, if you specify ESCAPE "z", the character strings z_ and z? in a string will stand for the literal characters _ and ? rather than be wild cards. Similarly, character strings z% and z* stand for the characters % and *. Finally, the character string zz stand for the single character z.

This expression is TRUE if the string "abc % def" include percent (%) character:

IF "abc % def" LIKE "% z% %" ESCAPE "z" THEN ...

 

Contact Us

Privacy Policy

Copyright © 2024 Querix, (UK) Ltd.