Suppose I have the following comma-delimited column value in MySQL: foo,bar,baz,bar,foo2
What is the best way to replace whatever is in the 4th position (in this case bar
) of this string with barAAA
(so that we change foo,bar,baz,bar,foo2
to foo,bar,baz,barAAA,foo2
)? Note that bar
occurs both in position 2 as well as position 4.
I know that I can use SUBSTRING_INDEX()
in MySQL to get the value of whatever is in position 4, but have not been able to figure out how to replace the value in position 4 with a new value.
I need to do this without creating a UDF or stored function, via using only the standard string functions in MySQL (http://dev.mysql.com/doc/refman/5.5/en/string-functions.html).