Beginner

184. Escaping LIKE Wildcards

Learn how to search for literal wildcard characters inside text.

📘 Lesson 184 of 728 ⏱ 9 min 🎯 Intermediate

Wildcard characters such as % and _ have special meanings in LIKE patterns. An escape mechanism can be used when the actual wildcard character needs to be searched as ordinary text.

Real business data may contain percentage signs, underscores, or other characters that should be treated as literal text.

Search for product descriptions containing the literal % character.

SQL
SELECT
    ProductName
FROM Products
WHERE ProductName LIKE '%10!%%' ESCAPE '!';

Escaping is useful in product descriptions, financial data, file names, codes, and data-quality searches.

  • LIKE wildcards have special meanings.
  • Escape characters allow literal wildcard searches.
  • ESCAPE syntax is supported by many SQL systems.
  • Database-specific syntax should be checked.
  • Escaping prevents unintended pattern matching.
Why are LIKE wildcards sometimes escaped?

They are escaped when the actual wildcard character needs to be searched as literal text.

What does ESCAPE do?

ESCAPE defines a character that can be used to treat wildcard characters as literal characters in a LIKE pattern.

Have you finished this lesson?

Introduction to SQL – All Lessons