oracle我刚刚接触不久,麻烦各位看看:
select caller_nbr,called_nbr,start_time,end_time,
(to_date(end_time,'yyyy-mm-dd hh24:mi:ss') - to_date(start_time,'yyyy-mm-dd hh24:mi:ss'))
 from tab_pub_calllog where called_nbr='18' order by start_time desc查询此语句时候报错,start_time,end_time的格式是:2009-03-01 19:28:16

解决方案 »

  1.   

    日期相减就是日期之间相差的天数
    比如
    SQL> select to_date('2009-03-01 19:28:16','yyyy-mm-dd hh24:mi:ss')-to_date('2009
    -02-01 19:28:16','yyyy-mm-dd hh24:mi:ss') rtn from dual;       RTN
    ----------
            28SQL> select to_date('2009-01-01 19:28:16','yyyy-mm-dd hh24:mi:ss')-to_date('2009
    -02-01 19:48:16','yyyy-mm-dd hh24:mi:ss') rtn from dual;       RTN
    ----------
    -31.013889你这里报什么错,你的start_time, end_time是什么类型的字段。
      

  2.   

    start_time 和 end_time是date字段 报 “ORA-01861:literal does not match format string”
      

  3.   

    是你的日期格式的问题。你用select sysdate from dual;看看你的日期格式。
      

  4.   

    select caller_nbr,called_nbr,start_time,end_time,
    end_time - start_time
    from tab_pub_calllog where called_nbr='18' order by start_time desc
      

  5.   

    因为2个时间字段,没有必要再通过to_date来转换格式了,会报错的。
    直接相减就可以了。
      

  6.   

    select caller_nbr,called_nbr,start_time,end_time, 
    end_time - start_time 
    from tab_pub_calllog where called_nbr='18' order by start_time desc 
      

  7.   


    那不需要用to_date了,直接相减。SQL> select to_date('2009-03-01 19:28:16','yyyy-mm-dd hh24:mi:ss')-to_date('2009 
    -02-01 19:28:16','yyyy-mm-dd hh24:mi:ss') rtn from dual; 注意我用的这里都是字符串的。to_date('2009-03-01 19:28:16','yyyy-mm-dd hh24:mi:ss')