How to Find and Replace Text in MySQL Database using SQL如何查找和替換文字MySQL數據庫中使用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). MySQL數據庫有一個方便簡單的字符串函數取代( ) ,使表數據的匹配字符串( from_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)語法的接替是接替( text_string , from_string , to_string )
MySQL reference MySQL的參考 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與所有出現的字符串from_string所取代字串to_string ,在匹配是區分大小寫的搜尋from_string 。 text_string can be retrieved from the a field in the database table too. text_string ,可從一個外地的數據庫表也。 Most SQL command can be REPLACE() function, especially SELECT and UPDATE manipulation statement.大多數SQL命令可以接替( )函數,尤其是選擇和更新操縱發言。
For example:例如:
update TABLE_NAME set FIELD_NAME = replace(FIELD_NAME, ‘find this string’, ‘replace found string with this string’);更新TABLE_NAME一套FIELD_NAME =取代( FIELD_NAME ,發現此字串' , '替換字符串發現此字串' ) ;
update client_table set company_name = replace(company_name, ‘Old Company’, ‘New Company’)更新client_table一套company_name =取代( company_name , '老公司' , '新公司' )
The above statement will replace all instances of ‘Old Company’ to ‘New Company’ in the field of company_name of client_table table.上述聲明將取代所有的'老公司' ,以'新公司'領域的company_name的client_table就座。
Another example:另一個例子:
SELECT REPLACE(’www.mysql.com’, ‘w’, ‘Ww’);選擇接替( ' www.mysql.com ' , '瓦特' , '二戰' ) ;
Above statement will return ‘WwWwWw.mysql.com’ as result.上述聲明將返回' WwWwWw.mysql.com '的結果。
IMPORTANT : This is a machine translated page which is provided "as is" without warranty. 重要說明:這是一台機器翻譯網頁這是“原樣”提供,無保修。 Machine translation may be difficult to understand.機器翻譯可能很難理解。 Please refer to請參閱 original English article英文原文的文章 whenever possible.只要有可能。
Share and contribute or get technical support and help at共享和貢獻或獲得技術支持和幫助 My Digital Life Forums 我的數字生活論壇 . 。
Related Articles相關文章
- Remove or Trim First or Last Few Characters in MySQL Database with SQL刪除或修剪第一或過去的幾年中人物MySQL數據庫與SQL
- Check and Optimize MySQL Database Automatically with Crontab/Cron檢查和優化MySQL數據庫自動Crontab /玉米
- MySQL Database Performance Tuning Best Practices Video Tutorial MySQL數據庫性能調整的最佳做法視頻教程
- Enable Logging of Slow Queries (Slow Query Log) in MySQL Database啟用日誌記錄慢查詢(慢速查詢日誌)在MySQL數據庫
- MySQL Error 1170 (42000): BLOB/TEXT Column Used in Key Specification Without a Key Length MySQL的錯誤1170 ( 42000 ) :的BLOB /文本列中的關鍵規格沒有一個密鑰長度
- Download File Content Replacer to Search and Replace Text in Multiple Files下載文件的內容替代品,以搜索和替換文本多個文件
- Replace Notepad with Another Text Editor (eg. Notepad2 and Notepad++) in Vista取代記事本與另一文本編輯器(如記事本Notepad2和+ + )在Vista
- Download Free Ultra Hal Text-to-Speech Reader 1.0 for Convenient Text Reading免費下載超哈爾文本語音轉換器1.0 ,方便文本閱讀
- Download Free Ease PDF to Text Extractor v1.10 to Convert PDF to Text Files in Bulk免費下載PDF格式,以方便文本提取v1.10 PDF格式轉換為文本文件散裝
- Text Snip Keeps Your Text and Codes Formatting Safe from IM and Email文字剪斷讓您的文字和格式安全守則從IM和電子郵件


























May 4th, 2007 05:48 2007年5月4日05:48
Thanks a lot!多謝! You’ve saved my life!您救了我的命!
May 11th, 2007 10:38 07年5月11號10:38
Thanks for the help!謝謝您的幫助!
May 16th, 2007 07:24 07年5月16號7點24分
Excellent, just what I needed.優秀,正是我需要的。 Thanks!謝謝!
October 1st, 2007 18:23 2007年10月一日18:23
[...] The guide uses SQL statements based on MySQL replace() function to modify the database. [...]指南使用SQL語句MySQL的基礎上取代( )函數來修改數據庫。 To run SQL queries, login to MySQL database that houses WordPress tables [...]要運行SQL查詢,登錄到MySQL數據庫房屋WordPress的表格[...]
June 4th, 2008 15:43 2008年6月4日15:43
thanks, this is very helpful!!感謝,這是非常有益的!
September 1st, 2008 01:48 08年9月1日1時48
[...] The guide uses SQL statements based on MySQL replace() function to modify the database. [...]指南使用SQL語句MySQL的基礎上取代( )函數來修改數據庫。 To run SQL queries, login to MySQL database that houses WordPress tables [...]要運行SQL查詢,登錄到MySQL數據庫房屋WordPress的表格[...]
September 10th, 2008 21:52 2008年9月十日21:52
Algo k es puede resultar practico es cuando se necesita eliminar un caracter de una sere de registros es: k方塊算法以了解resultar practico方塊寬本身necesita eliminar取消字符的烏納塞雷德registros方塊:
update tabla1 set campo1=replace(campo1,’8′,”);更新tabla1一套campo1 =取代( campo1 , '8 ',");
esta sentencia eliminaria todos los 8 de la tabla: tabla1 del registro: campo1此sentencia eliminaria托多斯8日德拉塔夫拉: tabla1刪除註冊: campo1
(NOTA: las comillas son todas simples). (注意:拉斯comillas兒子托達單純) 。
October 9th, 2008 21:16 08年10月9日21:16
nececito reemplazar un tag con todo su relleno, por ejemplo nececito reemplazar聯合國標記控制的TODO洙relleno ,房ejemplo
update pagina_web.noticias set texto = replace(texto, “”>”,” ” )更新pagina_web.noticias一套texto =取代( texto , "">"," “ )
por vacio!!!房間vacio ! como hago para estandalizarla y que encuetre todo lo que esta dentro de科莫hago第estandalizarla及活動encuetre你的TODO樂此迪登特魯德
October 16th, 2008 01:00 2008年10月一十六日01:00
For me this is only working on exact replaces.對於我來說,這只是工作的確切取代。 I could replace all entries that are exact the searchterm but i could replace parts of an entry.我可以取代所有項目,確切的searchterm ,但我可以取代部分的條目。
October 21st, 2008 09:42 2008年10月21號09:42
[...] quick Google search led me to this helpful page. In short, I had to run the following: UPDATE wp_posts SET post_content = [...] [...]快速谷歌搜索使我這個有益的網頁。總之,我不得不執行下列:更新wp_posts集post_content = [...]
November 29th, 2008 00:46 2008年11月29日00:46
didn’t work for me…沒有工作的我...