我的数据库里存的数据有分 秒 可我在查询的时候 时间段不带分秒 这样查询会有问题吗啊
select * from GPSHISTY whereDATETIME between date'2008-4-10'and date'2008-4-19';
执行这句话的时候报错:文字与格式字符串不匹配

解决方案 »

  1.   

    select * from GPSHISTY where DATETIME between to_date('2008-4-10','yyyy-mm-dd hh:mi:ms')and to_date('2008-4-19','yyyy-mm-dd hh:mi:ms'); 
    这样
      

  2.   

    DATETIME 是表里的字段吧? 是什么类型的?试试这个:
    select * from GPSHISTY where 
    DATETIME between to_date('2008-4-10','yyyy-mm-dd') 
    and to_date('2008-4-19','yyyy-mm-dd'); 
    ------------------------------------------------------------------------------
    Blog: http://blog.csdn.net/tianlesoftware
    网上资源: http://tianlesoftware.download.csdn.net
    相关视频:http://blog.csdn.net/tianlesoftware/archive/2009/11/27/4886500.aspx
    Q Q 群:62697716 
      

  3.   


    数据库里有分和秒的话,就这样试试:select * from GPSHISTY where 
    DATETIME between to_date('2008-4-10 00:00:00','yyyy-mm-dd hh24:mi:ss') 
    and to_date('2008-4-19 00:00:00','yyyy-mm-dd hh24:mi:ss'); 
     
    日期一般就用to_date(str,format)格式转换 
    像'yyyy-mm-dd'这样的可以直接用date'xxxx'简化, 楼主的写法没有什么问题, 估计是字段类型不匹配..------------------------------------------------------------------------------
    Blog: http://blog.csdn.net/tianlesoftware
    网上资源: http://tianlesoftware.download.csdn.net
    相关视频:http://blog.csdn.net/tianlesoftware/archive/2009/11/27/4886500.aspx
    Q Q 群:62697716 
      

  4.   

    楼主看下字段是什么类型的先?
    ------------------------------------------------------------------------------
    Blog: http://blog.csdn.net/tianlesoftware
    网上资源: http://tianlesoftware.download.csdn.net
    相关视频:http://blog.csdn.net/tianlesoftware/archive/2009/11/27/4886500.aspx
    Q Q 群:62697716 
      

  5.   

    好了  你俩的都可以用 不过 select * from GPSHISTY where 
    DATETIME between to_date('2009-12-3','yyyy-mm-dd hh24:mi:ss') 
    and to_date('2009-12-3','yyyy-mm-dd hh24:mi:ss'); 这样的语句为什么查不出来呢?
      

  6.   

    select * from GPSHISTY where
    to_char(DATETIME,'YYYYMMDD') between '20080410' and '20080419'; 
      

  7.   


    这句语法有错。
    to_date('2009-12-3','yyyy-mm-dd hh24:mi:ss')
    to_date 函数中 2个参数类型不匹配。 ------------------------------------------------------------------------------
    Blog: http://blog.csdn.net/tianlesoftware
    网上资源: http://tianlesoftware.download.csdn.net
    相关视频:http://blog.csdn.net/tianlesoftware/archive/2009/11/27/4886500.aspx
    Q Q 群:62697716 
      

  8.   

    select * from GPSHISTY where 
    DATETIME between to_date('2009-12-3 00:00:00','yyyy-mm-dd hh24:mi:ss') 
    and to_date('2009-12-3 00:00:00','yyyy-mm-dd hh24:mi:ss'); 
    你这样查就可以
      

  9.   


    这个会报错,不会吧,
    select to_date('2008-02-02','yyyy-mm-dd hh24:mi:ss') from dual
      

  10.   

    to_date('2008-02-02','yyyy-mm-dd hh24:mi:ss') 默认是 2008-02-02 12:00:00
      

  11.   

    select * from GPSHISTY where 
    DATETIME between to_date('2009-12-3 00:00:00','yyyy-mm-dd hh24:mi:ss') 
    and to_date('2009-12-3 224:00:00','yyyy-mm-dd hh24:mi:ss');
      

  12.   

    select * from GPSHISTY where 
    trunc(to_date(DATETIME,'yyyy-mm-dd hh24:mi:ss'))=''2009-12-3'