随笔 - 16  文章 - 22  trackbacks - 0
<2009年1月>
28293031123
45678910
11121314151617
18192021222324
25262728293031
1234567

常用链接

留言簿(3)

我参与的团队

随笔分类

随笔档案

搜索

  •  

最新评论

阅读排行榜

评论排行榜

RT

表名:A
时间字段:ddatetime(datetime类型)

查询2003-2004年6月7日-7月8日数据。

1select * from A where (extract(year from ddatetime) between 2003 and 2004
2and (extract(month from ddatetime) between 6 and 7)
3and (extract(day from ddatetime) between 6 and 7)


extract只能取到日。小时,或者到秒,需要to_char。

查询2003-2004年6月7日-7月8日12时到20时数据。

 

1select * from A where (extract(year from ddatetime) between 2003 and 2004
2and (extract(month from ddatetime) between 6 and 7)
3and (extract(day from ddatetime) between 6 and 7and (to_char(ddatetime,'HH24'between 12 and 20)



以上查询在oracle可运行。

posted on 2009-01-18 14:12 rapin 阅读(2880) 评论(4)  编辑  收藏 所属分类: 数据库

FeedBack:
# re: sql 特定时间段的查询 2009-01-18 14:24 隔叶黄莺
8.0.5 下不行,9i 可以,不知道 8i 下行不行  回复  更多评论
  
# re: sql 特定时间段的查询 2009-01-18 14:41 rapin
@隔叶黄莺
谢谢提醒  回复  更多评论
  
# re: sql 特定时间段的查询 2009-01-18 22:47 duduli
以前自己用的是:把时间格式化,然后再进行sql查询。  回复  更多评论
  
# re: sql 特定时间段的查询 2009-01-21 15:22 思维时空
这个方法把SQL语句写的简洁了,但是ddatetime必须为date型,如果在此列上有索引,则ORACLE不会走索引.  回复  更多评论
  

只有注册用户登录后才能发表评论。


网站导航: