Primal Habits
It is currently Sun Mar 26, 2017 12:50 pm


Feed

Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Wed Feb 23, 2011 3:05 am 
Offline
User avatar

Joined: Sun Apr 25, 2010 1:02 pm
Posts: 115



How to Find & Replace Text in MySQL Database using SQL.

MySQL database has a handy and simple string function REPLACE() that allows table data with the matching string (from_string) to be replaced by new string (to_string). This is useful if there is need to search and replace a text string which affects many records or rows, such as change of company name, postcode, URL or spelling mistake.

The syntax of REPLACE is REPLACE(text_string, from_string, to_string)

MySQL reference describes REPLACE as function that returns the string text_string with all occurrences of the string from_string replaced by the string to_string, where matching is case-sensitive when searching for from_string. text_string can be retrieved from the a field in the database table too. Most SQL command can be REPLACE() function, especially SELECT and UPDATE manipulation statement.

Example:

update TABLE_NAME set FIELD_NAME = replace(FIELD_NAME, ‘find this string’, ‘replace found string with this new-string’);

update client_table set company_name = replace(company_name, ‘New Company’, ‘Old Company’)

The above statement will replace all instances of ‘New Company’ to ‘Old Company’ in the field of company_name of client_table table.

Another example:

SELECT REPLACE(‘www.website.com’, ‘w’, ‘Ww’);

Above statement would return ‘WwWwWw.website.com’ as the result.

_________________
Check Out RouterHead8080 T.V.



Share on FacebookShare on TwitterShare on TuentiShare on SonicoShare on FriendFeedShare on OrkutShare on DiggShare on MySpaceShare on DeliciousShare on Technorati
Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 7 hours [ DST ]


Related topics
 Topics   Author   Replies   Views   Last post 
There are no new unread posts for this topic. Restoring your Database via SSH

RouterHead8080

0

2967

Mon Nov 29, 2010 1:54 pm

RouterHead8080 View the latest post

There are no new unread posts for this topic. How to update / refresh / replace new facebook URL thumbnail

WhopperKing007

2

4967

Thu May 19, 2011 8:33 am

WhopperKing007 View the latest post

There are no new unread posts for this topic. Blood, milk and mucus could one day replace silicon chips

ReadAllAboutIt1619

0

3106

Sun Mar 18, 2012 3:25 pm

ReadAllAboutIt1619 View the latest post

There are no new unread posts for this topic. Wordpress Replace/Remove Default Header Image Twenty Eleven

RouterHead8080

0

1062

Tue Nov 22, 2011 11:09 am

RouterHead8080 View the latest post

There are no new unread posts for this topic. MYSQL B.5.2.10. Packet too large

RouterHead8080

0

2802

Mon Nov 29, 2010 1:19 pm

RouterHead8080 View the latest post

 


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron

Affiliates    Terms of use    Privacy policy   

Primal Habits, a Sceptersoft Company
Copyright © 2010 - 2017 Sceptersoft LLC. All rights reserved.