POSITION

Applies to: ✅ Data 360 SQL ✅ Tableau Hyper API

Returns the location of a substring within a string.

Syntax

position(<substring> in <string> [, start => s] [, occurrence => n])

Arguments

Required

  • <substring>: The substring to search for.
  • <string>: The string to search within.

Optional

  • start: The position to start searching from.
  • occurrence: Which occurrence to find (nth occurrence).

Returns

Returns an integer that represents the 1-based position of the substring, or 0 if not found.

Examples

Find Substring Position

Locate a substring within a string.

SELECT position('om' in 'Thomas') AS result;

Returns 3, indicating 'om' starts at position 3.

Find Substring Starting From Position

Locate the second occurrence of a substring within a string starting from position 16.

SELECT position('sea' in 'Sally sells sea shells by the sea shore, how many sea shells did she sell?')

Returns 51, indicating that the second 'sea' after position 16 starts at position 51.

Related Documentation