数据库版本:9.2.0.1.0
现表A中有一属性为date的列timeline,此列记录时间信息,精确到秒,例如:2008-4-23 8:52:28
现在查询的需求如下:1.查找时间timeline 为 2008-4-01日前的行2.查找时间 timeline 在 2008-4-01到2008-04-24之间的行3.查询时间 timeline 为2008-04的行的SQL语句,希望各位高手指点,多谢。

解决方案 »

  1.   

    1.select * from A where timeline < to_date('2008-04-01')2. select * from A where timeline >= to_date('2008-04-01') and timeline <= to_date('2008-04-24') 3.select * from A where to_char(timeline,'YYYY-MM') = '2008-04'  
      

  2.   

    谢谢ehsgs的答复,我试了一下,不过有如下报错:信息如下:ORA-01861:literal does not match format string这个不知道是不是date格式的限制有关,timeline的时间精确到秒。
      

  3.   

    是那句出的错另外看下你的nls_date_format的格式是啥
      

  4.   

    ehsgs 他回复的是错误的。Oracle对Date的操作是要处理格式的。
    TO_DATE('Date of parameter,'Date of format')
      

  5.   

    1.select * from A where timeline < to_date('2008-04-01 00:00:00','yyyy-mm-dd hh:mi:ss')2. select * from A where timeline >= to_date('2008-04-01 00:00:00','yyyy-mm-dd hh:mi:ss') and timeline <= to_date('2008-04-24 00:00:00','yyyy-mm-dd hh:mi:ss')  3.select * from A where substr(to_char(timeline,'yyyy-mm-dd hh:mi:ss'),1,7) = '2008-04' 
      

  6.   

    1.select * from A where timeline < to_date('20080401','yyyymmdd')2. select * from A where timeline between to_date('20080401','yyyymmdd') and to_date('20080424','yyyymmdd')   3.select * from A where timeline  = to_date('200804' ,'yyyymm')
      

  7.   

    select * from tab where t.timeline<to_date('2008-04-01','yyyy-mm-dd');select * from tab where t.timeline<to_date('2008-04-25','yyyy-mm-dd') and  t.timeline>to_date('2008-04-01','yyyy-mm-dd') ;select * from tab where to_char(timeline,'yyyy-mm')='2008-04'