zl程序教程

您现在的位置是:首页 >  数据库

当前栏目

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

mysqlSQL 字符串 语句 替换 表中
2023-06-13 09:14:01 时间

核心语句:

UPDATE`cdb_pms`
SET`subject`=REPLACE(`subject`,"Welcometo","欢迎光临")


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

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

mysql>selecthost,userfromuser whereuser="testuser";
+-----------------------+----------+
|host                 |user    |
+-----------------------+----------+
|localhost.localdomain|testuser|
+-----------------------+----------+

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

mysql>updateusersethost=REPLACE(host,"main","slave")whereuser="testuser";      
QueryOK,1rowaffected(0.00sec)
Rowsmatched:1 Changed:1 Warnings:0

mysql>selecthost,userfromuser whereuser="testuser";                            
+------------------------+----------+
|host                  |user    |
+------------------------+----------+
|localhost.localdoslave|testuser|
+------------------------+----------+

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


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

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

mysql>selectid,typefromitemslimit10;
+--------+--------+
|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>updateitemssettype=replace(type,"79","78");

QueryOK,17536rowsaffected(0.72sec)
Rowsmatched:17536 Changed:17536 Warnings:0
再查询:

mysql>selectid,typefromitemslimit10;
+--------+--------+
|id    |type  |
+--------+--------+
|  0001|790000|
|  0002|790000|
|  0003|790000|
|  0004|790000|
|  0005|790000|
|150419|790000|
|150420|790000|
|150421|790000|
|150422|790000|
|150423|790000|
+--------+--------+
10rowsinset(0.00sec)

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