隨筆 - 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 閱讀(2921) 評(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ǔ)句寫的簡(jiǎn)潔了,但是ddatetime必須為date型,如果在此列上有索引,則ORACLE不會(huì)走索引.  回復(fù)  更多評(píng)論
            
          主站蜘蛛池模板: 西和县| 鄂温| 井陉县| 温宿县| 大埔县| 罗甸县| 韶关市| 渭南市| 武功县| 三门峡市| 湘潭市| 忻州市| 浪卡子县| 上蔡县| 苏尼特左旗| 手游| 石门县| 花莲县| 商水县| 楚雄市| 林口县| 雷山县| 大石桥市| 昭平县| 南华县| 托克托县| 崇阳县| 嵩明县| 聂荣县| 伊宁市| 襄垣县| 井陉县| 邢台市| 山东| 岳普湖县| 琼中| 库尔勒市| 都匀市| 郁南县| 土默特右旗| 昌乐县|