LOCATE()

Overview

Returns the position of the first occurrence of a substring within a string.

USAGE

LOCATE(substring, string[, position])

Argument Name

Description

substring

The substring to locate

string

The string to search

position

The starting position for the search

DETAILS

LOCATE() is a string function that returns the position of the first occurrence of a substring a string.

The optional position argument specifies a starting position for the search, which allows for the finding of subsequent string matches within the string after the first match.

A 0 is returned if the substring is not found within the string.

A NULL is returned if any argument is NULL.

SYNONYMS

SCHEMA

PARAMETERS

SKYSQL

PRIVILEGES

EXAMPLES

SELECT LOCATE('abcd', 'abcacbabdcabceabcd');
+--------------------------------------+
| LOCATE('abcd', 'abcacbabdcabceabcd') |
+--------------------------------------+
|                                   15 |
+--------------------------------------+
SET @str = 'abcacbabdcabceabcd';
SELECT LOCATE('abc', @str) AS m1,
       LOCATE('abc', @str, 2) AS m2,
       LOCATE('abc', @str, 12) AS m3;
+------+------+------+
| m1   | m2   | m3   |
+------+------+------+
|    1 |   11 |   15 |
+------+------+------+

ERROR HANDLING

FEATURE INTERACTION

RESPONSES

DIAGNOSIS

ISO 9075:2016

CHANGE HISTORY

Release Series

History

23.09

  • Present starting in MariaDB Xpand 23.09.1.

6.1

  • Present starting in MariaDB Xpand 6.1.0.

6.0

  • Present starting in MariaDB Xpand 6.0.3.

5.3

  • Present starting in MariaDB Xpand 5.3.13.

Release Series

History

6.0

  • Present starting in MariaDB Xpand 6.0.3.

5.3

  • Present starting in MariaDB Xpand 5.3.13.

Release Series

History

6.1

  • Present starting in MariaDB Xpand 6.1.0.

EXTERNAL REFERENCES