把非空的字段number(7,4)的数据合理转行成varchar2(32)类型

        把非空的字段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/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值