MariaDB: LOCATE Function
This MariaDB tutorial explains how to use the MariaDB LOCATE function with syntax and examples.
Description
The MariaDB LOCATE function returns the location of the first appearance of a substring in a string.
Syntax
The syntax for the LOCATE function in MariaDB is:
LOCATE( substring, string, [start_position ] )
Parameters or Arguments
- substring
- The substring to search for in string.
- string
- The string to search.
- start_position
- Optional. The position in string where the search will start. If omitted, it defaults to 1 which is the first position in the string.
Note
- The first position in string is 1.
- If substring is not found in string, then the LOCATE function will return 0.
- When searching for the location of a substring in a string, the LOCATE function does not perform a case-sensitive search.
- The POSITION function is a synonym for the LOCATE function.
Applies To
The LOCATE function can be used in the following versions of MariaDB:
- MariaDB 10
Example
Let's look at some MariaDB LOCATE function examples and explore how to use the LOCATE function in MariaDB.
For example:
SELECT LOCATE('T', 'TechOnTheNet.com'); Result: 1 SELECT LOCATE('t', 'TechOnTheNet.com'); Result: 1 SELECT LOCATE('t', 'TechOnTheNet.com', 2); Result: 7 SELECT LOCATE('t', 'TechOnTheNet.com', 8); Result: 12 SELECT LOCATE('h', 'TechOnTheNet.com', 5); Result: 8 SELECT LOCATE('the', 'TechOnTheNet.com', 1); Result: 7 SELECT LOCATE('this', 'TechOnTheNet.com'); Result: 0
Advertisements