现在表里有个字段BEGIN_TIME是DATE类型,(date跟varchar有什么区别),然后记录形式如下
2007-1-19 15:22:47现在要查找这个月里1月5号13:00到17:00的记录select * from test where to_???????????????????????????????????
2007-1-19 15:22:47现在要查找这个月里1月5号13:00到17:00的记录select * from test where to_???????????????????????????????????
to_date(2007-1-5 13:00:00,'HH:MI:SS');对不?
日期格式应改为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')
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'); 就应该可以了
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');