现在表里有个字段BEGIN_TIME是DATE类型,(date跟varchar有什么区别),然后记录形式如下
2007-1-19 15:22:47现在要查找这个月里1月5号13:00到17:00的记录select * from test where to_???????????????????????????????????

解决方案 »

  1.   

    select * from test where BEGIN_TIME between to_date('2007-01-19 13:00:00','YYYY-MM-DD 24hi:mm:ss') and to_date('2007-01-05 17:00:00','YYYY-MM-DD 24hi:mm:ss')
      

  2.   

    select * from test where BEGIN_TIME between to_date(2007-1-5 13:00:00,'YYYY-MM-DD HH:MI:SS') and
    to_date(2007-1-5 13:00:00,'HH:MI:SS');对不?
      

  3.   

    上面的错了
    日期格式应改为hh24:mi:ss,语句如下
    select * from test where BEGIN_TIME between to_date('2007-01-19 13:00:00','YYYY-MM-DD hh24:mi:ss') and to_date('2007-01-05 17:00:00','YYYY-MM-DD hh24:mi:ss')
      

  4.   

    BEGIN_TIME是DATE类型
    date 类型的数据是不能存到时间的 只能存到日期
    比如  2007-1-19 15:22:47   在数据库里面存的数值只是  2007-01-19所以 按照你的查询条件 只需要这么写
    select * from test where BEGIN_TIME between to_date('2007-01-19','YYYY-MM-DD') and to_date('2007-01-05','YYYY-MM-DD');  就应该可以了
      

  5.   

    OracleDBA群35903017,欢迎加入。
      

  6.   

    Paladin_china(大仙) 的回复大体是正确的,但是FORMAT格式有问题,应是:
    select * from test where BEGIN_TIME between to_date('2007-01-19 13:00:00','YYYY-MM-DD HH24:MI:SS') and to_date('2007-01-05 17:00:00','YYYY-MM-DD HH24:MI:SS');
      

  7.   

    to_char(date,'yyyy-mm-dd')to_date(char,'yyyy-mm-dd')