一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

dedecms SQL命令运行器批量替换指定字符串例子

时间:2014-09-08 编辑:简简单单 来源:一聚教程网

查询指定 archives 表

select * from 你的表前缀_archives limit 1

这个表是主表了,我们查询一条出来看看,结果如下

运行SQL:select * from 你的表前缀_archives where id =1466,共有1条记录,最大返回100条!

记录:1
id:1466
typeid:110
typeid2:0
sortrank:1238913636
flag:c,p
ismake:1
channel:1
arcrank:0
click:33119
money:0
title:可爱的动态nomoQQ表情图片
shorttitle:
color:
writer:
source:
litpic:http://upload.111com.net/allimg/c090405/123Y13349440-1SH6.jpg
pubdate:1238913636
senddate:1238913636

现在我们可以锁定到id =1466 记录

select litpic from 你的表前缀_archives where id =1466;

执行结果

运行SQL:select litpic from 你的表前缀_archives where id =1466;,共有1条记录,最大返回100条!
记录:1
litpic:http://upload.111com.net/allimg/c090405/123Y13349440-1SH6.jpg

好了现在我们需要把litpic 字段中的http://upload.111com.net 替换成 /uploads/ 这种,这些我们可以使用update replace来实现

例子

update 你的表前缀_archives set  `litpic`=replace(litpic, 'http://upload.111com.net', '/uploads')  WHERE  id=1466

我们来执行看看结果 成功执行1个SQL语句,好现在我们来查询一下执行结果是不是我们想要的,再执行

select litpic from 你的表前缀_archives where id =1466;

确定执行提示

运行SQL:select litpic from 你的表前缀_archives where id =1466;,共有1条记录,最大返回100条!
记录:1
litpic:/uploads/allimg/c090405/123Y13349440-1SH6.jpg

看提示没有错误,我们在地址栏看看图片正确,查看是没有问题了,现在我们来批量替换

select litpic from 你的表前缀_archives where litpic like '%http://upload.111com.net%'

这样我们查一下是为了防止后面替换不会替换没有http://upload.111com.net了,也防止了sql出错导致数据库全部替换掉了

update 你的表前缀_archives set  `litpic`=replace(litpic, 'http://upload.111com.net', '/uploads')  where litpic like '%http://upload.111com.net%'

成功执行1个SQL语句!

我们再查一下看

运行SQL:select litpic from 你的表前缀_archives where litpic like '%http://upload.111com.net%',无返回记录!

这样代表替换成功了 转载注明来源http://www.111com.net

热门栏目