如表名为tb2
第一步先去除所有空格
update tb2 set value=REPLACE(value,' ','');
第二步去除所有已有的'.'
update tb2 set value=REPLACE(value,'.','');
1位字母的:
update tb2 set value=CONCAT(value,'.') where length(value)=1 and value!='.';
2位字母的:
update tb2 set value=CONCAT(SUBSTRING(value,1,1),'.',SUBSTRING(value,2,1),'.') where length(value)=2 and value not like '%.%';
3位字母的:
update tb2 set value=CONCAT(SUBSTRING(value,1,1),'.',SUBSTRING(value,2,1),'.',SUBSTRING(value,3,1),'.') where length(value)=3 and value not like '%.%';
4位字母的:
..................
以些类推。
如果由程序控制的话,可以从以下规律着手:
变量t为字母位数,m为累加变量为1到t,先去除空格和已有'.'后的更新语句为:
update tb2
set
value=CONCAT(SUBSTRING(value,1,1),'.',SUBSTRING(value,2,1),'.',................,SUBSTRING(value,t,1),'.')
where length(value)=t and value not like '%.%';
即:value的值为CONCAT()里面重复SUBSTRING(value,m,1),'.',重复的次数由字母位数t决定,第一次m为1,第二次m为2,。。。。第t次m=t,然后结束CONCAT()。条件为 length(value)=t且value里本身没有'.'。
温馨提示:答案为网友推荐,仅供参考