Skip to content
SQLSimplified
string

SPLIT_PART()

Splits a string on a delimiter and returns the Nth piece.

Description

SPLIT_PART divides a string into pieces using a delimiter and returns the n-th piece (1-based). It's the simplest way to pull a field out of a delimited value — like the domain from an email or a segment of a path — without regular expressions.

Syntax

SPLIT_PART(string, delimiter, n)

Parameters

NameDescriptionOptional
stringThe text to split.No
delimiterThe separator.No
nWhich part to return (1 = first).No

Return Type

Returns a VARCHAR. If n is out of range it typically returns an empty string.

Examples

Employees & Departments

Loading database engine...

Employees & Departments

Loading database engine...

Pairs well with POSITION

If the delimiter can repeat, SPLIT_PART is easier than SUBSTRING + POSITION for grabbing a known segment.

Common Mistakes

  • 0-based index. n starts at 1, not 0.
  • Out-of-range n. Returns empty string (not NULL) in many engines — don't rely on NULL to detect missing parts.
  • Multi-character delimiter. The delimiter is treated as a single unit; it won't split on any of its characters individually.

See also: SUBSTRING, POSITION, STRING_AGG.

Search

Search lessons, functions, examples, and practice problems