LIKE

Description

The LIKE operator is used in SQL queries to match strings based on a specified pattern. It can help you find data that contains specific characters or patterns. When using the LIKE operator, you can use wildcards to represent one or more characters.

Parameters

  • str (string): The original string to be matched.
  • pattern (string): The pattern string containing wildcards.

Return Value

Returns a boolean value indicating whether str matches pattern.

Wildcard Explanation

  • %: Represents any number of characters (including zero characters).
  • _: Represents any single character.

Usage Example

  1. Match strings that start with "Hello":
SELECT 'HelloWorld' LIKE 'Hello%';

Results:

true
  1. Through a string with two characters "lo":
SELECT 'HelloWorld' LIKE '%lo%';

Results:

true
  1. Match strings that contain "lo" and end with "ld":
SELECT 'HelloWorld' LIKE '%lo_ld';

Results:

false
  1. Use a single character wildcard to match strings containing "oW":
SELECT 'HelloWorld' LIKE 'Hello_W%';

Results:

true
  1. Combine with the NOT keyword to find strings that do not match a specific pattern:
SELECT 'HelloWorld' NOT LIKE 'Hello%';

Results:

false