Updated on 2026-11-06 GMT+08:00

split_part1

The split_part1 function is used to split the string str by the delimiter separator and return the substring from the start part to the end part (inclusive).

Syntax

split_part1(string <str>, string <separator>, bigint <start>[, bigint <end>]) 

Parameters

Table 1 Parameter descriptions

Parameter

Mandatory

Type

Description

str

Yes

STRING

The string to be split.

separator

Yes

STRING

A STRING type constant. The delimiter used for splitting. Can be a single character or a string.

start

Yes

BIGINT

A BIGINT type constant, must be greater than 0. Indicates the starting part number (starting from 1).

end

No

BIGINT

A BIGINT type constant, greater than or equal to start. Indicates the ending part number. Can be omitted. When omitted, it is equal to the value of start, returning the part specified by start.

Return Values

Returns a value of type STRING.

  • If the value of start is greater than the actual number of parts after splitting, for example, the string is split into 4 parts and start is greater than 4, an empty string is returned.
  • If separator does not exist in str and start is specified as 1, the entire str is returned. If str is an empty string, an empty string is returned.
  • If separator is an empty string, the original string str is returned.
  • If end is greater than the number of parts, the substring starting from start is returned.
  • If str is not of type STRING, BIGINT, DOUBLE, DECIMAL, or DATETIME, an error is returned.
  • If any parameter value is NULL (except separator), NULL is returned.

Example Code

Returns aa.

select split_part1('aa,bb,cc,dd', ',', 1);  

Returns aa,bb.

select split_part1('aa,bb,cc,dd', ',', 1, 2); 

Returns an empty string.

select split_part1('aa,bb,cc,dd', ',', 10); 

Returns aa,bb,cc,dd.

select split_part1('aa,bb,cc,dd', ':', 1); 

Returns an empty string.

select split_part1('aa,bb,cc,dd', ':', 2); 

Returns aa,bb,cc,dd.

select split_part1('aa,bb,cc,dd', '', 1); 

Returns bb,cc,dd.

select split_part1('aa,bb,cc,dd', ',', 2, 6); 

Returns NULL.

select split_part1('aa,bb,cc,dd', ',', null);