mysql替换表中的字符串的sql语句

2016-02-19 10:37 2 1 收藏

清醒时做事,糊涂时读书,大怒时睡觉,无聊时关注图老师为大家准备的精彩内容。下面为大家推荐mysql替换表中的字符串的sql语句,无聊中的都看过来。

【 tulaoshi.com - 编程语言 】

核心语句:

UPDATE `cdb_pms` SET `subject` = REPLACE(`subject`, 'Welcome to', '欢迎光临')

mysql替换字段里数据内容部分字符串

mysql替换表的字段里面内容,如例子:

mysql select host,user from user  where user='testuser';
+-----------------------+----------+
| host                  | user     |
+-----------------------+----------+
| localhost.localdomain | testuser |
+-----------------------+----------+

update字段host的内容,把"main"改成"slave",用REPLACE

mysql update user set host=REPLACE(host,'main','slave') where user='testuser';      
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql select host,user from user  where user='testuser';                            
+------------------------+----------+
| host                   | user     |
+------------------------+----------+
| localhost.localdoslave | testuser |
+------------------------+----------+

(本文来源于图老师网站,更多请访问https://www.tulaoshi.com/bianchengyuyan/)

由查询结果到,数据已经更新成功


因为服务器上安了一流拦截系统,所以dede的交替功能不好使.只能手动在phpadmin中SQL:
update dede_addonarticle  set body=replace(body ,'大法','方法') 

mysql替换表的字段里面内容,如例子:

mysql select id,type from items limit 10;
+--------+--------+
| id     | type   |
+--------+--------+
|   0001 | 780000 |
|   0002 | 780000 |
|   0003 | 780000 |
|   0004 | 780000 |
|   0005 | 780000 |
| 150419 | 780000 |
| 150420 | 780000 |
| 150421 | 780000 |
| 150422 | 780000 |
| 150423 | 780000 |
+--------+--------+

把type字段中的“78”改成“79” 用replace函数
 

sql如下:

mysql update items set type=replace(type,'79','78');

Query OK, 17536 rows affected (0.72 sec)
Rows matched: 17536  Changed: 17536  Warnings: 0
再查询:

mysql select id,type from items limit 10;
+--------+--------+
| id     | type   |
+--------+--------+
|   0001 | 790000 |
|   0002 | 790000 |
|   0003 | 790000 |
|   0004 | 790000 |
|   0005 | 790000 |
| 150419 | 790000 |
| 150420 | 790000 |
| 150421 | 790000 |
| 150422 | 790000 |
| 150423 | 790000 |
+--------+--------+
10 rows in set (0.00 sec)

由查询结果到,数据已经更新成功

(本文来源于图老师网站,更多请访问https://www.tulaoshi.com/bianchengyuyan/)

来源:https://www.tulaoshi.com/n/20160219/1595262.html

延伸阅读
SQL中也可以用格式字符串定制日期转字符串 -------------------------------------------------------------------------------- 这篇论坛文章(赛迪网技术社区)介绍了SQL Server利用格式字符串定制日期转换为字符串的具体方法,更多内容请参考下文: 在C#中用惯了DateTime.ToString("yyyy-MM-dd"),DateTime.ToString("MM/dd/yyyy")这种日...
Delphi中的字符串 ——摘自网络 一:各种字符串  字符串是Object Pascal所有数据类型中最有用的类型。许多函数以字符串为传递参数。由于在Delphi中字符串的定义和使用有各种方式,包括Pascal中典型的字符串(String),Delphi支持的长字符串(ANSIString),类似于C语言的字符数组(Array of Char),指向字符的...
基本要求:需安装WORD FunctionWordReplace(FileNameAsString,SearchStringAsString,ReplaceStringAsString,OptionalSaveFileAsString="",OptionalMatchCaseAsBoolean=False)AsInteger OnErrorGoToErrorMsg'函数运行时发生遇外或错误,转向错误提示信息 DimwordAppAsNewWord.Application DimwordDocAsNewWord.Docu...
标签: SQLServer
/* author:amjn date:2003-03-28 version:1.0 function:替换text,ntext列中的字符串(不支持中文) */ declare @ptr varbinary(16) declare @amjnId int declare @Position int,@len int set @len=datalength('ILOVEHJL') declare wux_Cursor scroll Cursor for select textptr([Name]),[amjnId] from USA201 for re...
标签: ASP
  自己可以修改myreplace函数,实现复杂的替换.呵呵,好象用处不大.主要是看看如何读取access表和字段列表 <% '#################################### '替换数据库内容 lamking 2005-8-22 'http://www.lamking.com QQ:628557 '#################################### Dim Db,Connstr,conn,rs,rs2,str1,str2,I str1="abcd" '要替换的字符...

经验教程

917

收藏

66
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部