表名:A
時(shí)間字段:ddatetime(datetime類型)
查詢2003-2004年6月7日-7月8日數(shù)據(jù)。
1
select * from A where (extract(year from ddatetime) between 2003 and 2004)
2
and (extract(month from ddatetime) between 6 and 7)
3
and (extract(day from ddatetime) between 6 and 7)

2

3

extract只能取到日。小時(shí),或者到秒,需要to_char。
查詢2003-2004年6月7日-7月8日12時(shí)到20時(shí)數(shù)據(jù)。
1
select * from A where (extract(year from ddatetime) between 2003 and 2004)
2
and (extract(month from ddatetime) between 6 and 7)
3
and (extract(day from ddatetime) between 6 and 7) and (to_char(ddatetime,'HH24') between 12 and 20)

2

3

以上查詢?cè)趏racle可運(yùn)行。