SPLIT_PART
Descriptionβ
The SPLIT_PART function splits a string into multiple parts according to the specified separator and return one of the parts.
Syntaxβ
SPLIT_PART ( <str>, <separator>, <part_index> )
Parametersβ
Parameter | Description |
---|---|
<str> | The string to be split |
<separator> | The string used for splitting |
<part_index> | The index of the part to be returned. Starting from 1 |
Return Valueβ
Returns the specified part of the string split according to the delimiter. Special cases:
- If any of the parameters is NULL, NULL is returned.
- When
<part_index>
is 0, NULL is returned.
Examplesβ
select split_part("hello world", " ", 1);
+----------------------------------+
| split_part('hello world', ' ', 1) |
+----------------------------------+
| hello |
+----------------------------------+
SELECT split_part('apple,banana,cherry', ',', 0);
+-------------------------------------------+
| split_part('apple,banana,cherry', ',', 0) |
+-------------------------------------------+
| NULL |
+-------------------------------------------+