This function is used to truncate the string before the count separator of str. If the value of count is positive, the string is truncated from the left. If the value of count is negative, the string is truncated from the right.
substring_index(string <str>, string <separator>, int <count>)
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
str |
Yes |
STRING |
String to be truncated |
separator |
Yes |
STRING |
Separator of the STRING type |
count |
No |
INT |
Position of the delimiter |
The return value is of the STRING type.
If the value of any input parameter is NULL, NULL is returned.
The value hello.world is returned.
SELECT substring_index('hello.world.people', '.', 2);
The value world.people is returned.
select substring_index('hello.world.people', '.', -2);