Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Using MySql replace function

MySql has a very useful Function replace() which allows you to Replace substring or characters. It is really useful while working with huge database table where you want to update certain values with another value. Its syntax is quite simple.


REPLACE ( field_name, 'find_string', 'replacement_string' );

To update some values in database table use query as follows using replace function.


UPDATE tutorials SET topic = REPLACE (topic, 'Php', 'Php MySql');

You can also run a select query using this function if you don't want to update table but want to fetch data as replaced. This will only output replaced values and there will be no changes in database.


SELECT REPLACE (topic, 'Php', 'Php MySql') as new_topic
FROM tutorials
WHERE topic = 'Php';



This post first appeared on Altaf Hussain's Blog, please read the originial post: here

Share the post

Using MySql replace function

×

Subscribe to Altaf Hussain's Blog

Get updates delivered right to your inbox!

Thank you for your subscription

×