Hello,
I need to write a stored procedure in MySQL that loops through all rows in a table (the column types are TEXT and VARCHAR) and replaces certain characters in the column values with another character. For example, a certain column contains the text "ababa" and I want to change it to "acaca".
I can''t quite figure out the part about replacing a character in a string with another and could use some help with this!
Thank you very much!
Sylvain
解决方案You need to sort out if you''re wanting to replace a char or a string. The letter ''b'' is different than the word "ababa", so you should be a little more clear there: are you wanting to replace ''b'' with ''c'' or "ababa" with "acaca"?
Regardless, you''re going to want to use the UPDATE and REPLACE commands.
UPDATE your_table SET your_field=(REPLACE(your_field,''old-text'',''new-text'')
old-text is (are) the character(s) you wish to replace, and new-text is (are) the character(s) you''ll replace them with.
Cheers,
-jc