How to find and replace text in the MySQL database using SQL

December 31st, 2008 | by whazup |

MySQL database is a simple and useful string function REPLACE () which allows data to the table with the strings (from_string) to be replaced by new string (to_string). This is useful if you need to find and replace a text string that affects many rows or records, such as change of name, zip code, URL, or spelling.

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

Reference described in REPLACE function that returns the string text_string with all occurrences of the string from_string replaced by the chain to_string, where correspondence is sensitive when looking for from_string. text_string can be obtained from the field in the database table as well. Most SQL queries can be REPLACE() function, and in particular the handling SELECT and UPDATE.

For example:

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

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

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

Another example:

SELECT REPLACE(‘www.mysql.com’, ‘w’, ‘x’);

Above statement will return ‘xxx.mysql.com’ as result.

Related Posts:

  • How to Use Torrent
    If you wanted to download big file like movie, etc, this is the tool. Read this how to use Torrent at here. How to use it; 1. download torrent client example Bitcomet(www.bitcomet.com), azureus(...
  • How to Find Designer Clothing on a Budget
    Designer clothing is desirable for so many people but not so many people can afford it. Here are some ways to help you find designer gear at a more affordable price. Steps 1. Shop at used cloth...
  • Restore File Backup .sql Ke Database MySQL
    1. Disini saya berasumsi MySQL sudah terinstall dikomputer Anda dan berjalan sebagai mana mestinya dan juga setidaknya Anda sudah bisa menggunakan MySQL (jika belom ya searching aja di inet banyak sek...

Tags: , , , , , ,

Post a Comment