Home  >  Article  >  Database  >  sql积累--替换指定字段数据中的指定内容_MySQL

sql积累--替换指定字段数据中的指定内容_MySQL

WBOY
WBOYOriginal
2016-06-01 13:08:381384browse

这次遇到这个需求:数据库中的图片连接以前全是小图,要换成中图,我开始想用java代码全部查出来,再遍历list,替换修改图片连接中的字符。由于数据两百万多,一下查询出来是个问题,依次查询(0-1000,1000-2000,...),也麻烦。想过重新导入数据,就导入所需要尺寸的图片URL,后来,想到用mysql自带的函数才处理REPLACE(filed,'regex','str') 相当于java中的replace,只是这里指定了替换的哪个字段filed.

图片有三种:

大:http://media.digikey.com/Photos/Skyworks%20Solutions%20Photos/SE2564L-R_tmb.jpg

中:http://media.digikey.com/Photos/Skyworks%20Solutions%20Photos/SE2564L-R_sml.jpg

小:http://media.digikey.com/Photos/Skyworks%20Solutions%20Photos/SE2564L-R_tmb.jpg

由于有规律,替换起来很容易。

UPDATE t_product_copy tpc
SET tpc.img= REPLACE(img,'_tmb', '_sml')

执行结果:(该字段有很多数据为空,不修改)

[SQL] UPDATEt_product_copy tpc

SET tpc.img= REPLACE(img,'_tmb', '_sml')

受影响的行: 1153979
时间: 41.572ms
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:mysql---union的用法_MySQLNext article:MySql实现分页_MySQL