---
title: split_part function
description: Learn the syntax of the split\_part function of the SQL language in Databricks SQL and Databricks Runtime.
canonical_url: https://docs.databricks.com/aws/en/sql/language-manual/functions/split_part
---

# `split_part` function

**Applies to:** ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks SQL ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks Runtime 11.3 LTS and above

Splits `str` around occurrences of `delim` and returns the `partNum` part.

## Syntax

```
split_part(str, delim, partNum)
```

## Arguments

* `str`: A `STRING` expression to be split.
* `delimiter`: A `STRING` expression serving as delimiter for the parts.
* `partNum`: An `INTEGER` expression electing the part to be returned.

## Returns

A `STRING`.

If `partNum` >= 1: The `partNum`s part counting from the beginning of `str` will be returned.

If `partNum` \<= -1: The `abs(partNum)`s part counting from the end of `str` will be returned.

If `partNum` is beyond the number of parts in `str`: The function returns an empty string.

If `partNum` is 0: `split_part` raises an [INVALID\_INDEX\_OF\_ZERO](https://docs.databricks.com/aws/en/error-messages/error-classes.md#invalid_index_of_zero).

## Common error conditions

* [INVALID\_INDEX\_OF\_ZERO](https://docs.databricks.com/aws/en/error-messages/error-classes.md#invalid_index_of_zero)

## Examples

```sql
> SELECT '->' || split_part('Hello,world,!', ',', 1) || '<-';
  ->Hello<-

> SELECT '->' || split_part('Hello,world,!', ',', 2) || '<-';
  ->world<-

> SELECT '->' || split_part('Hello,world,!', ',', 100) || '<-';
  -><-

> SELECT '->' || split_part('Hello,world,!', ',', -2) || '<-';
  ->world<-

> SELECT '->' || split_part('Hello,world,!', ',', -100) || '<-';
  -><-

> SELECT '->' || split_part('', ',', 1) || '<-';
  -><-

> SELECT '->' || split_part('Hello', '', 3) || '<-';
  -><-

> SELECT '->' || split_part('Hello,World,!', ',', 0) || '<-';
  ERROR: INVALID_INDEX_OF_ZERO

> SELECT split_part('5A6B7' COLLATE UTF8_BINARY, 'a', 1);
  5A6B7

> SELECT split_part('5A6B7' COLLATE UTF8_LCASE, 'a', 1);
  5

> SELECT split_part('a,b,c', ',', 0);
  Error: INVALID_INDEX_OF_ZERO
```

## Related functions

* [`split` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/split.md)
