隨筆 - 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 閱讀(2928) 評論(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不會走索引.  回復  更多評論
            
          主站蜘蛛池模板: 枝江市| 英山县| 鄂尔多斯市| 滁州市| 新丰县| 多伦县| 林州市| 兴城市| 淅川县| 永顺县| 根河市| 晋中市| 甘谷县| 莲花县| 周口市| 靖远县| 额尔古纳市| 西华县| 炎陵县| 韶关市| 浠水县| 克什克腾旗| 普兰店市| 泽普县| 平果县| 隆昌县| 湖北省| 会同县| 宜黄县| 浦东新区| 博客| 夏邑县| 宜兰县| 宁波市| 浏阳市| 修文县| 宕昌县| 竹北市| 南和县| 阳城县| 嫩江县|