Skip to main content

STARTS_WITH

Description​

The STARTS_WITH function checks if a string starts with a specified prefix. Returns true if the string starts with the specified prefix; otherwise returns false.

Syntax​

STARTS_WITH(<str>, <prefix>)

Parameters​

ParameterDescription
<str>The string to check. Type: VARCHAR
<prefix>The prefix string to match. Type: VARCHAR

Return Value​

Returns BOOLEAN type.

Special cases:

  • Returns NULL if any argument is NULL

Examples​

  1. Successful match
SELECT starts_with('hello world', 'hello');
+-------------------------------------+
| starts_with('hello world', 'hello') |
+-------------------------------------+
| 1 |
+-------------------------------------+
  1. Failed match
SELECT starts_with('hello world', 'world');
+-------------------------------------+
| starts_with('hello world', 'world') |
+-------------------------------------+
| 0 |
+-------------------------------------+