Overview
ThePOSITION()
function returns the position of the first occurrence of a substring in a string. It works the same as
STRPOS, but it has slightly different syntax.
Syntax
The syntax for this function is as follows:Examples
Example 1
This query looks for the position of the substringworld
within the string Hello, world!
.
world
, which is 7.
Example 2
The query looks for the position of the substring123
within the string 1a2b3c
.
123
is found starting at position 1, the result would be 1.
Example 3
The query tries to find the position of the substringabc
within the string xyz
.
abc
is not found in xyz
, the result would be 0.
Example 4
This query searches for the position of the substringcde
within the string cde
.
cde
is the entire string, the result would be 1.