摆脱自我

做男人就得狠一点
posts - 10, comments - 0, trackbacks - 0, articles - 0

connect by构建时间段表

Posted on 2007-06-13 14:37 *飞雪冲天* 阅读(182) 评论(0)  编辑  收藏 所属分类: oracle
例1:
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')));
例2:
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'

只有注册用户登录后才能发表评论。


网站导航: