dedecms使用SQL命令批量替换指定字符串的方法
2015-04-05 16:02
357 查看
本文实例讲述了dedecms使用SQL命令批量替换指定字符串的方法。分享给大家供大家参考。具体分析如下:
几年前做的一个QQ站现在把资料整过来了,但是发现有些litpic缩略图中的路么地址不对了,以前我都是使用phpmyadmin替换,今天我发现可以直接使用SQL命令运行器来解决,下面来看我一个替换litpic中指定路径地址.
查询指定 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.jb51.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.jb51.net/allimg/c090405/123Y13349440-1SH6.jpg
好了现在我们需要把litpic 字段中的http://upload.jb51.net 替换成 /uploads/ 这种,这些我们可以使用update replace来实现.
例子:
代码如下:
update 你的表前缀_archives set `litpic`=replace(litpic, 'http://upload.jb51.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.jb51.net%'
这样我们查一下是为了防止后面替换不会替换没有http://upload.jb51.net了,也防止了sql出错导致数据库全部替换掉了.
代码如下:
update 你的表前缀_archives set `litpic`=replace(litpic, 'http://upload.jb51.net', '/uploads') where litpic like '%http://upload.jb51.net%'
成功执行1个SQL语句,我们再查一下看.
运行SQL:
select litpic from 你的表前缀_archives where litpic like '%http://upload.jb51.net%'
无返回记录!
希望本文所述对大家的dedecms建站有所帮助。
几年前做的一个QQ站现在把资料整过来了,但是发现有些litpic缩略图中的路么地址不对了,以前我都是使用phpmyadmin替换,今天我发现可以直接使用SQL命令运行器来解决,下面来看我一个替换litpic中指定路径地址.
查询指定 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.jb51.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.jb51.net/allimg/c090405/123Y13349440-1SH6.jpg
好了现在我们需要把litpic 字段中的http://upload.jb51.net 替换成 /uploads/ 这种,这些我们可以使用update replace来实现.
例子:
代码如下:
update 你的表前缀_archives set `litpic`=replace(litpic, 'http://upload.jb51.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.jb51.net%'
这样我们查一下是为了防止后面替换不会替换没有http://upload.jb51.net了,也防止了sql出错导致数据库全部替换掉了.
代码如下:
update 你的表前缀_archives set `litpic`=replace(litpic, 'http://upload.jb51.net', '/uploads') where litpic like '%http://upload.jb51.net%'
成功执行1个SQL语句,我们再查一下看.
运行SQL:
select litpic from 你的表前缀_archives where litpic like '%http://upload.jb51.net%'
无返回记录!
希望本文所述对大家的dedecms建站有所帮助。
相关文章推荐
- dedecms使用SQL命令批量替换指定字符串的方法
- python使用xlrd实现检索excel中某列含有指定字符串记录的方法
- Python使用中文正则表达式匹配指定中文字符串的方法示例
- python使用xlrd实现检索excel中某列含有指定字符串记录的方法
- PHP使用strstr()函数获取指定字符串后所有字符的方法
- golang通过反射使用json字符串调用struct的指定方法及返回json结果
- PHP使用strstr()函数获取指定字符串后所有字符的方法
- js中使用eval()方法将字符串转换成日期格式、并获取指定时间的日期
- php使用指定字符列表生成随机字符串的方法
- C#截取指定长度中英文字符串方法
- Path.Combine (合并两个路径字符串)方法的一些使用细节
- 使用substring()方法完成字符串替换.
- 一个使用特殊符号分割的字符串解码方法(Delphi版)
- 使用split分割多字符的字符串的方法
- C#截取指定长度中英文字符串方法
- C#截取指定长度中英文字符串方法
- C#截取指定长度中英文字符串方法 (收藏)
- 使用BCP方法时,注意因为这是命令行方法,拼写字符串时不要有回车符!
- Path.Combine (合并两个路径字符串)方法的一些使用细节
- C#中使用split分割字符串的几种方法