把非空的字段number(7,4)的数据合理转行成varchar2(32)类型,为了number(7,4)的数据0.6500转换成varchar2(32)时为.65,需要合理的把.65类似的数据换成0.65
--1 查询该字段不为空的行数
select count(*) from mlog_comp_explain t where t.quanting_max is not null;
--2 增加一个临时字段
alter table mlog_comp_explain add (tempcol varchar2(32));
--3 把需要修改字段类型的字段数据存放到临时字段中
update mlog_comp_explain t set t.tempcol=t.quanting_max;
--4 把不符合数据类型的数据转行一下,如.65换成0.65, 7.21还是7.21
select t.quanting_max,
case when(substr(to_char(tempcol),0,1)='.')
then 0 end || to_char(tempcol) as "temp"
from mlog_comp_explain t
where t.tempcol is not null;
--5 不符数据类型的数据转行一下,如.65换成0.65, 7.21还是7.21
update mlog_comp_explain s set
s.tempcol=
(
case when(substr(to_char(tempcol),0,1)='.')
then 0 end || to_char(tempcol)
)
--6清空字段的数据,这样则可以改变该字段的类型了
update mlog_comp_explain t set t.quanting_max=null;
--7 改变该字段的类型
alter table mlog_comp_explain modify quanting_max varchar2(32);
--8 把临时字段的数据放回原来的字段中
update mlog_comp_explain t set t.quanting_max=t.tempcol;
--9 删除临时字段
alter table mlog_comp_explain drop column tempcol;
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/12778571/viewspace-578015/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/12778571/viewspace-578015/