oracle 时间24小时和12小时格式问题


在oracle数据库的表格中,有一列的数据类型是时间类型,但是显示的是12小时制,就是分上下午的,我在做界面的时候需要统计数据库指定表中的时间列对应白天时间(比方说早上7点到晚上7点)的字段,但是从java类中查询的时候,输出结果是十二小时制,比方说下午五点,是17点,但是无法在数据库中查到,比方说我这样写:
String sql = "select avg(temperature),avg(airPressure),avg(humidity),avg(wind) from environment where t.stationNo = ? " + "and t.inDate>=? and t.inDate<=? and (to_char(dateObserv, 'hhmiss')>'080000' and (to_char(dateObserv, 'hhmiss')<'165959'))";
return super.getDefaultManager().find(sql, listInfo.getFirstNo(), listInfo.getMaxNo(), stationNo, startInData, endInData);
这种情况就把白天和晚上的时间都 查了,
请问这种该怎么实现?

java oracle

觉醒的豆腐 12 years, 4 months ago

时间进制转换一下就行了。
12小时制 hhmiss

   
  select to_char(date,'hhmiss') from table
 

24小时制

   
  select to_char(date,'hh24miss') from table
 

你的SQL就是这样写了:

   
  String sql = "select avg(temperature),avg(airPressure),avg(humidity),avg(wind) from environment where t.stationNo = ? " + "and t.inDate>=? and t.inDate<=? and (to_char(dateObserv, 'hh24miss')>'080000' and (to_char(dateObserv, 'hh24miss')<'165959'))";
 

一天佑一天 answered 12 years, 4 months ago

Your Answer