MySQL does not include a function to split a delimited string. However, it’s very easy to create your own function.
Create function syntax
A user-defined function is a way to extend MySQL with a new function that works like a native MySQL function.
CREATE [AGGREGATE] FUNCTION function_name RETURNS {STRING|INTEGER|REAL|DECIMAL}
To create a function, you must have the INSERT privilege for the <mysql> database.
Split delimited strings
The following example function takes 3 parameters, performs an operation using an SQL function, and returns the result.
Function
CREATE FUNCTION SPLIT_STR( x VARCHAR(255), delim VARCHAR(12), pos INT ) RETURNS VARCHAR(255) RETURN REPLACE(SUBSTRING(SUBSTRING_INDEX(x, delim, pos), LENGTH(SUBSTRING_INDEX(x, delim, pos -1)) + 1), delim, '');
Usage
SELECT SPLIT_STR(string, delimiter, position)
Example
SELECT SPLIT_STR('a|bb|ccc|dd', '|', 3) as third; +-------+ | third | +-------+ | ccc | +-------+
10.28.7.209=DC1:RAC1
10.28.7.218=DC1:RAC2
10.40.7.206=DC2:RAC1
10.40.7.191=DC2:RAC2
default=DC1:r1
bin/nodetool -h 10.40.7.206 ring
Address Status State Load Owns Token
131291297286969809762394636651102920798
10.40.7.191 Up Normal 11.01 GB 25.02% 3713143261524536428796724100157456993
10.28.7.218 Up Normal 21.79 GB 25.00% 46247024543280544328625128736684811735
10.40.7.206 Up Normal 11.01 GB 24.97% 88731726328828585514925390034962410388
10.28.7.209 Up Normal 22.19 GB 25.01% 131291297286969809762394636651102920798
With randompartitioner I inserted 1M records, and was expecting 1M rows on each node. I ended up with 1M each on DC1:RAC1 and DC1:RAC2, while ended up with just 75K each on DC2:RAC1 and DC2:RAC2.