我想把表里的一个字符型的现实日期的字段,如:2011-01-19 转换成201101这种格式,下面是我的代码
select to_char(product_time,'YYYYMM') from hmi_sim
总是报错ora-01722:无效数字
请指教怎么解决

解决方案 »

  1.   

    -- 字段是字符类型的话,直接用 replace()函数!
      

  2.   

    select replace(product_time,'-','') as product_time from hmi_sim;
      

  3.   

    scott@SZTYORA> select replace('2011-01-25','-','') as product_time from dual;PRODUCT_TIME
    ----------------
    20110125
      

  4.   

    存日期为什么要用字符型呢,不是有date类型嘛
    select to_char(to_date('2011-01-19','yyyy-mm-dd'),'yyyymm') from dual
      

  5.   


    select replace(substr('2011-01-19',1,7),'-','') from dual;REPLACE(SUBSTR('2011-01-19',1,7),'-','')
    --------------------------------------------
    201101