📣
TiDB Cloud Premium is now in public preview. Unlimited growth, instant elasticity, advanced security for enterprise workloads. Try it out →

POSITION



POSITION(substr IN str) is a synonym for LOCATE(substr,str). Returns the position of the first occurrence of substring substr in string str. Returns 0 if substr is not in str. Returns NULL if any argument is NULL.

Syntax

POSITION(<substr> IN <str>)

Arguments

ArgumentsDescription
<substr>The substring.
<str>The string.

Return Type

BIGINT

Examples

SELECT POSITION('bar' IN 'foobarbar') +----------------------------+ | POSITION('bar' IN 'foobarbar') | +----------------------------+ | 4 | +----------------------------+ SELECT POSITION('xbar' IN 'foobar') +--------------------------+ | POSITION('xbar' IN 'foobar') | +--------------------------+ | 0 | +--------------------------+

Was this page helpful?