Skip to main content
Version: 0.0.1

LOCATE

Categories: String

LOCATE

Searches for the first occurrence of the first argument in the second argument and if found, returns the position the of the first argument in the second argument. The first character in a string is position 1. Returns 0 if the substring isn't found in the expression.

Syntax

LOCATE(substring varchar, expression varchar [, start int32]) → int32

  • substring: Substring to search for in the expression.
  • expression: The input expression to search.
  • start (optional): Position to start the search from.

Examples

{{< codeheader "LOCATE example" >}}

SELECT LOCATE('an','banana', 3)
-- 4

{{< codeheader "LOCATE example" >}}

SELECT LOCATE('no','banana')
-- 0

LOCATE(substring varchar, expression varchar) → int32

  • substring: Substring to search for in the expression.
  • expression: The input expression to search.

Examples

{{< codeheader "LOCATE example" >}}

SELECT LOCATE('an','banana')
-- 2