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

          常用鏈接

          留言簿(3)

          我參與的團(tuán)隊(duì)

          隨筆分類

          隨筆檔案

          搜索

          •  

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          RT

          表名:A
          時(shí)間字段:ddatetime(datetime類型)

          查詢2003-2004年6月7日-7月8日數(shù)據(jù)。

          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只能取到日。小時(shí),或者到秒,需要to_char。

          查詢2003-2004年6月7日-7月8日12時(shí)到20時(shí)數(shù)據(jù)。

           

          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)



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

          posted on 2009-01-18 14:12 rapin 閱讀(2919) 評(píng)論(4)  編輯  收藏 所屬分類: 數(shù)據(jù)庫

          FeedBack:
          # re: sql 特定時(shí)間段的查詢 2009-01-18 14:24 隔葉黃鶯
          8.0.5 下不行,9i 可以,不知道 8i 下行不行  回復(fù)  更多評(píng)論
            
          # re: sql 特定時(shí)間段的查詢 2009-01-18 14:41 rapin
          @隔葉黃鶯
          謝謝提醒  回復(fù)  更多評(píng)論
            
          # re: sql 特定時(shí)間段的查詢 2009-01-18 22:47 duduli
          以前自己用的是:把時(shí)間格式化,然后再進(jìn)行sql查詢。  回復(fù)  更多評(píng)論
            
          # re: sql 特定時(shí)間段的查詢 2009-01-21 15:22 思維時(shí)空
          這個(gè)方法把SQL語句寫的簡(jiǎn)潔了,但是ddatetime必須為date型,如果在此列上有索引,則ORACLE不會(huì)走索引.  回復(fù)  更多評(píng)論
            

          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 普定县| 泗水县| 吉隆县| 兴业县| 修武县| 乃东县| 辽宁省| 女性| 吴桥县| 扎赉特旗| 光山县| 抚顺县| 金平| 高密市| 棋牌| 绥宁县| 同仁县| 丰县| 贵港市| 杭锦后旗| 宜城市| 垫江县| 微博| 青阳县| 正安县| 庆城县| 平泉县| 敖汉旗| 阜南县| 济宁市| 渑池县| 昭觉县| 唐河县| 上饶市| 宁波市| 娄烦县| 富蕴县| 西充县| 龙海市| 肃宁县| 邻水|