#define DEF_DEADLINE_TIME    9:00:00字段为time,value,数据库中时间使用字符串形式保存的(形如:2:00:01)用户从DateTimePicker1中选定一个时间。
我要查询用用户选定的时间到DEF_DEADLINE_TIME这段时间之间的记录,sql语句该怎么写?

解决方案 »

  1.   

    select * 
    from tb
    where time_col 
    between to_date(DateTimePicker1.TOSTRING(),'HH24:MI:SS') and to_date(DEF_DEADLINE_TIME,'HH24:MI:SS')
      

  2.   

    --sel_time 选择时间
    SELECT *
      FROM a
     WHERE to_date(to_char(SYSDATE, 'yyyy-mm-dd') || ' ' || TIME, 'yyyy-mm-dd hh24:mi:ss') BETWEEN
           to_date(to_char(SYSDATE, 'yyyy-mm-dd') || ' ' || sel_time, 'yyyy-mm-dd hh24:mi:ss') AND
           to_date(to_char(SYSDATE, 'yyyy-mm-dd') || ' ' || DEF_DEADLINE_TIME, 'yyyy-mm-dd hh24:mi:ss');
    --最好不要这样,数据量大将不能用上索引(列上使用了函数),可以将时间中时分秒都补足2位直接字符串比较
    --形如:time between sel_time and DEF_DEADLINE_TIME