piliskys

            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
            25 隨筆 :: 0 文章 :: 40 評論 :: 0 Trackbacks
          問題:查出在2001年5年到2004年1月的所有年月格式為yyyymm(其實也是別人問到我這樣一個相關的問題)
          select to_char(to_date('200105','yyyymm'),'yyyy')+ b.bb||'00'+a.aa  ff
               
          from 
              (
          select level aa from dual connect by 1=1 and level <13 ) a, 
              (
          select level-1 bb from dual connect by 1=1 and level <=
              (to_char(to_date(
          '200402','yyyymm'),'yyyy'- to_char(to_date('200105','yyyymm'),'yyyy')+1)  ) b
              
          where  to_char(to_date('200105','yyyymm'),'yyyy')+ b.bb||'00'+a.aa  >='200105'
              
          and to_char(to_date('200105','yyyymm'),'yyyy')+ b.bb||'00'+a.aa  <='200402'

          不用其它表,就可以構造出一個時間表來,注意:connect by據說只支持oracle 9i 及以上
          posted on 2005-11-23 17:44 霹靂火 閱讀(515) 評論(1)  編輯  收藏 所屬分類: oracle數據庫

          評論

          # re: connect by構建時間段表 2005-11-24 09:51 霹靂火
          select * from (
          select to_char(add_months(to_date('200501','yyyymm'), rownum), 'yyyymm') from dual
          connect by rownum<months_between(to_date('200512','yyyymm'),to_date('200501','yyyymm')));
          發現別人一種寫法更好  回復  更多評論
            

          主站蜘蛛池模板: 达州市| 集安市| 米脂县| 昆山市| 鄂温| 安溪县| 黄龙县| 玛沁县| 佳木斯市| 邵武市| 萍乡市| 平阳县| 余干县| 福州市| 怀宁县| 前郭尔| 武胜县| 将乐县| 英吉沙县| 外汇| 黄平县| 灌云县| 措美县| 将乐县| 广宗县| 菏泽市| 德钦县| 固镇县| 芒康县| 唐山市| 永安市| 湖南省| 太保市| 正定县| 阳城县| 武强县| 阜新市| 河津市| 伊宁市| 高台县| 六枝特区|