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

很文博客hinvn.com 数据库评论85字数 1644阅读模式
广告也精彩

替换字段里数据内容部分字符串,这个在替换网址呀什么的最经常用了,发布一下做个笔记.

核心语句:文章源自很文博客https://www.hinvn.com/很文博客-https://www.hinvn.com/60144.html

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

mysql替换字段里数据内容部分字符串文章源自很文博客https://www.hinvn.com/很文博客-https://www.hinvn.com/60144.html

mysql替换表的字段里面内容,如例子:文章源自很文博客https://www.hinvn.com/很文博客-https://www.hinvn.com/60144.html

mysql> select host,user from user  where user='testuser';
+-----------------------+----------+
| host                  | user     |
+-----------------------+----------+
| localhost.localdomain | testuser |
+-----------------------+----------+文章源自很文博客https://www.hinvn.com/很文博客-https://www.hinvn.com/60144.html

update字段host的内容,把"main"改成"slave",用REPLACE文章源自很文博客https://www.hinvn.com/很文博客-https://www.hinvn.com/60144.html

mysql> update user set host=REPLACE(host,'main','slave') where user='testuser';文章源自很文博客https://www.hinvn.com/很文博客-https://www.hinvn.com/60144.html

Query OK, 1 row affected (0.00 sec)文章源自很文博客https://www.hinvn.com/很文博客-https://www.hinvn.com/60144.html

Rows matched: 1  Changed: 1  Warnings: 0

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

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

因为服务器上安了一流拦截系统,所以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)

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

工具:作品在线观看

女优:最新作品观看

中文:国语在线观看

weinxin
我的微信
扫一扫更精彩
大家的支持是我更新的动力!!!
 
广告也精彩
匿名

发表评论

匿名网友
:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:
确定

拖动滑块以完成验证