我需要更改最后一列中的第5个字符。
例如,
m
。JPG 到
b
。JPG 如何使用MySQL查询?
答案 0 :(得分:4)
update your_table
set col = concat(substring(col, 1, length(col) -5), 'b', substring(col, -4))
where length(col) > 5 --if you really need.
答案 1 :(得分:1)
怎么样
update your_table
set col = replace(col, 'm.jpg', 'b.jpg')
答案 2 :(得分:1)
检查
select col, if(length(col)<5,col,concat(substr(col,1,length(col)-5),'X',substr(col,length(col)-3,5))) from table;
并基于它运行更新:
update table set col=concat(substr(col,1,length(col)-5),'X',substr(col,length(col)-3,5)) where length(col)>5;