LOCATE(substr,string[,position])

Description: Without position, returns the character position of the first occurrence of substr within string, or 0 if it does not occur.

With position, returns the first occurrence of substr at or after that number of characters from the start of string.

Examples:

  • LOCATE('a','Harold Jacobs') returns 2.

  • LOCATE('JACOBS','Harold Jacobs') returns 8.

  • LOCATE(BINARY 'JACOBS','Harold Jacobs') returns 0.

  • LOCATE('a','Harold Jacobs',6) returns 9.

See also: INSTR(), POSITION()

Get Sams Teach Yourself MySQL in 21 Days, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.