oracle 格式化日期

博客介绍了将日期格式为DD-MM-YY HH24:MI:SS.000 上午的数据转换为date类型的方法,即先使用截取字符串的方式使格式正常,再进行to_date转换。

当日期格式为DD-MM-YY HH24:MI:SS.000 上午 这种格式的时候转成date类型的方法

使用最笨的方法进行截取字符串

select (case when 时间 is null then '9999'
             else '20'||substr(时间,instr(时间,'-',-1,1)+1,2) end )||        --年
       (case when 时间  is null then '12' 
             when substr(substr(时间 ,instr(时间 ,'-',1)+1,2),2) = '月' 
                  then '0'||substr(时间 ,instr(时间 ,'-',1)+1,1)
             else substr(时间 ,instr(时间 ,'-',1)+1,2)end)||                 --月
                (case when 时间 is null then '31'
                      else substr(时间,1,2) end )||                          --日
       (case when 时间 is null then '121212'
             else replace(substr(时间,instr(时间,'-',-1,1)+4,8),'.','') end) --时分秒         
                           from 表

这样子格式就是正常的了然后在进行to_date转换就可以了 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值