SPLIT_PART
Description
The SPLIT_PART function is used to split a string (str) by a specified delimiter (delim) and return the substring at the specified position (partNum).
Parameter Description
- str (string): The string to be split.
- delim (string): The string used as a delimiter to split the input string into multiple substrings.
- partNum (bigint): Specifies the position of the substring to return. When partNum is greater than 0, it indicates the partNum-th substring from the left; when partNum is less than 0, it indicates the partNum-th substring from the right. If partNum exceeds the number of substrings after splitting, an empty string is returned. partNum cannot be 0.
Return Result
Returns a string (string) representing the substring at the specified position.
Usage Example
Notes
- When partNum is 0, the function will return an error.
- If the input string or delimiter is empty, the function will return an empty string.
- When partNum is negative, the position of the substring is calculated from the right side.
- If multiple characters are needed as delimiters, multiple characters can be used consecutively or a regular expression can be used for splitting.