select * from time where
to_date(tTime,'yyyy-MM-dd HH24mi') >='1031'  and to_date(tTime,'yyyy-MM-dd HH24mi') <='1940'
时间列是20120223200404这样的现在我需要根据客户输入的时间点  比如201203221022 到 201203221055  这段时间内的记录  为什么错了啊

解决方案 »

  1.   

    比较格式混乱掉了。用date型和字符型比较大小当然是不行的。
      

  2.   

    你要实现什么功能?判断年份是否在1031和1940年之间??
    看你的数据,时间列是char型的,那就不用to_date了:
    select * from time where substr(tTime,1,4) >='1031' and substr(tTime,1,4) <='1940';
      

  3.   


    首先你这SQL犯了两个错误1、to_date(tTime,'yyyy-MM-dd HH24mi') 错误
    正确应该是 to_date(tTime,'yyyy-mm-dd hh24:mi')2、to_date(tTime,'yyyy-MM-dd HH24mi') >='1031' 这个等式错误
    左边TO_DATE 出来的是日期格式  而右边是 字符串格式,肯定会报错
    正确写法:
    select * from time 
    where to_date(tTime,'yyyy-mm-dd hh24:mi') >= to_date('201203221022','yyyy-mm-dd hh24:mi')
    and to_date(tTime,'yyyy-MM-dd HH24:mi') <= to_date('201203221055','yyyy-mm-dd hh24:mi')
      

  4.   

    你这样的话是选取1031年到1940年的数据,楼主的意思应该是选取“小时”之间的数据吧
    不管要选取那个时间段,最好能都包括进去 You may as well like this:
    select * from time 
    where substr(tTime,1,14)>='201203221022' and substr(tTime,1,14)<='201203221055' ;
      

  5.   


    ERROR: ORA-01861: literal does not match format string