当前位置: 代码迷 >> Oracle技术 >> oracle 字符转为时间的有关问题
  详细解决方案

oracle 字符转为时间的有关问题

热度:61   发布时间:2016-04-24 08:29:03.0
oracle 字符转为时间的问题
数据库字段是varchar2(20)存放的是数据是( 2012-05-31 23:11:12 ),也有可能是NULL
我现在怎么取数据,如果有数据就格式为YYYYMMDDH24MISS 如果是NULL 转为0
用SQL语句实现

------解决方案--------------------
SQL code
with t1 as(     select '2012-05-31 23:11:12' c1 from dual     union all    select '' c1 from dual    union all     select '2012-05-22 22:22:22' c1 from dual )select nvl(to_char(to_date(c1,'yyyy-mm-dd hh24:mi:ss'),'yyyymmddhh24miss'),0) c1from t1        c1------------------------1    201205312311122    03    20120522222222
  相关解决方案