All Products
Search
Document Center

MaxCompute:LIKE

Last Updated:Dec 21, 2023

LIKE is a special character in SQL and is used for pattern matching. In most cases, LIKE is used with the WHERE clause of the SELECT statement to filter string data that conforms to a specific pattern. This topic describes common wildcard characters in LIKE and provides examples on how to use the common wildcard characters.

Usage notes

MaxCompute SQL supports only the UTF-8 character set. If data is encoded in other formats, the calculation results may be invalid.

LIKE wildcard characters

  • % indicates to match multiple characters.

  • _ indicates to match a single character.

If you want to match % or _, escape % or _ before you perform the match operation. For example,

escape % to \\%, and escape _ to \\_.

Examples

  • Example 1: true is returned.

    select 'abcd' like 'ab%'; 
  • Example 2: false is returned.

    select 'abcd' like 'ab_';
  • Example 3: true is returned.

    select 'ab_cde' like 'ab\\_c%';

References

For more information about how to more precisely match or replace characters, see Regular expression specifications.