隨筆 - 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ù)庫(kù)

          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語(yǔ)句寫(xiě)的簡(jiǎn)潔了,但是ddatetime必須為date型,如果在此列上有索引,則ORACLE不會(huì)走索引.  回復(fù)  更多評(píng)論
            
          主站蜘蛛池模板: 甘孜县| 石渠县| 松原市| 绩溪县| 江口县| 沙坪坝区| 泰和县| 绥芬河市| 荣成市| 乳山市| 延寿县| 宽城| 四川省| 封丘县| 花莲县| 台江县| 巴彦淖尔市| 罗山县| 阜新| 南城县| 黑水县| 阿拉善盟| 六盘水市| 晋宁县| 尼勒克县| 南通市| 涡阳县| 万山特区| 托克托县| 弋阳县| 金沙县| 收藏| 南汇区| 砀山县| 金寨县| 调兵山市| 临朐县| 姜堰市| 伊金霍洛旗| 朔州市| 蒙自县|