Skip to content
Advertisement

MySql trigger to replace text

everybody!

I have a trigger to replace text BEFORE INSERT to table, i have a text in which need change one word

SET NEW.shipping_method = CASE WHEN NEW.shipping_method LIKE 'weight' THEN 'Svars' ELSE 
NEW.shipping_method END

But this command change all text who contain word weight to svars.

Thanks

P.S. I read a documentation on sql but can’t find the correct definition ????

Advertisement

Answer

If you need to replace a word in text, then use replace():

SET NEW.shipping_method = REPLACE(NEW.shipping_method, 'weight', 'Svars')
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement