I want to extract the substrings from a string in mysql. The string contains multiple substrings separated by commas(','). I need to extract these substrings using any mysql functions.
For example :
Table Name: Product
-----------------------------------
item_code name colors
-----------------------------------
102 ball red,yellow,green
104 balloon yellow,orange,red
I want to select the colors field and extract the substrings as red,yellow and green as separated by comma.
Check the use of SPLIT_STR function here at line 64 to 69
Based on https://blog.fedecarg.com/2009/02/22/mysql-split-string-function/, here is a way to access a value from a delimiter separated array:
here are the docs for the string operators for reference: https://dev.mysql.com/doc/refman/8.0/en/string-functions.html
A possible duplicate of this: Split value from one field to two
Unfortunately, MySQL does not feature a split string function. As in the link above indicates there are User-defined Split function.
A more verbose version to fetch the data can be the following: