Chinaunix

标题: mysql concat,substring用法 [打印本页]

作者: yanjing5462    时间: 2007-06-28 10:28
标题: mysql concat,substring用法

在工作中碰到一个Mysql字段更新问题
在custom表中有一个tariffurl的值中有如下情况:
uploadfiles ariff2007031172720306698.jpg以及uploadfiles ariff2007031172720306690.jpg;uploadfiles ariff2007031172720306691.jpg形式
要更改成uploadfiles/tariff/200703/1172720306698.jpg及 uploadfiles/tariff/200703/1172720306690.jpg;uploadfiles/tariff200703/1172720306691.jpg 形式
可以综合利用substring函数和cancat函数来实现,步骤如下:
1、 update custom set tariffurl=concat('uploadfiles/tariff/200703/',substring(tariffurl,24)) where tariffurl like 'uploadfiles ariff200703%'
2、update custom set tariffurl=concat(substring(tariffurl,1,55),'/tariff/200703/',substring(tariffurl,68))
where tariffurl like 'uploadfiles/tariff/200703/%' and tariffurl like'%;uploadfiles %'
substring(filed,m):截取filed字段从第m个字符开始到结束的字符串;
substring(filed,m,n):截取filed字段从第m个字符开始的长度为n的字符串;
cancat(string1,sting2,……):将string1、string2, ……字符串连接起来。


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/2326/showart_330212.html




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2