日期:2014-05-16  浏览次数:20950 次

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) c1
from t1


        c1
------------------------
1    20120531231112
2    0
3    20120522222222