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相关文章
- How to Move WordPress Blog to New Domain or Location如何移动的WordPress所博客新的网域或位置
- Remove or Trim First or Last Few Characters in MySQL Database with SQL删除或修剪第一或过去数字符在MySQL数据库与SQL
- Change or Set MySQL Long Query Time Value for log-slow-queries改变或设置MySQL的长期查询时间价值为登录慢的疑问
- How to Backup and Restore (Export and Import) MySQL Databases Tutorial如何备份和恢复(出口和进口)的MySQL数据库补习
- Enable Logging of Slow Queries (Slow Query Log) in MySQL Database启用日志记录慢查询(慢速查询日志)在MySQL数据库
- WordPress MySQL SQL Query Error in WPDB Class在WordPress MySQL的SQL查询错误在wpdb级
- MySQL Database Performance Tuning Best Practices Video Tutorial MySQL数据库性能调整的最佳做法视频教程
- Install Web Server in Windows XP with Apache2, PHP5 and MySQL4 - Part 4安装Web服务器在Windows XP的Apache2 , php5和mysql4 -第4部分
- Change and Reset MySQL root Password改变和重置MySQL的root密码
- MySQL Error 1170 (42000): BLOB/TEXT Column Used in Key Specification Without a Key Length MySQL的错误1170 ( 42000 ) : BLOB的/文本列中使用的主要规格,没有一个密钥长度



















May 4th, 2007 05:48 2007年5月4日5时48分
Thanks a lot!感谢了很多! You’ve saved my life!您保存了我的生命!
May 11th, 2007 10:38 2007年5月11日10时38分
Thanks for the help!感谢您的帮助!
May 16th, 2007 07:24 2007年5月16日7时24分
Excellent, just what I needed.优秀的,只要我需要什么。 Thanks!谢谢!
October 1st, 2007 18:23 2007年10月1日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!!感谢,这是非常有帮助!