日期:2014-05-17 浏览次数:20892 次
select to_date('2011'||lpad(2,2,'0'),'YYYYMM')+rownum-1 from dual connect by rownum<=(select to_date('2011'||lpad(2+1,2,'0'),'YYYYMM')-to_date('2011'||lpad(2,2,'0'),'YYYYMM') from dual)
------解决方案--------------------
--根据年月获取起始日期 select max(sdate) m_date,min(sdate) n_date from ( select to_char(to_date('2011'||'-01', 'YYYY-MM') + rownum - 1, 'YYYY-MM-DD') as sdate from dual connect by rownum <= 365) where to_char(to_date(sdate,'yyyy-mm-dd'),'MM')=2 m_date n_date ----------------------------------- 1 2011-02-28 2011-02-01 --根据年和季度获取起始日期 select max(sdate) m_date,min(sdate) n_date from ( select to_char(to_date('2011'||'-01', 'YYYY-MM') + rownum - 1, 'YYYY-MM-DD') as sdate from dual connect by rownum <= 365) where to_char(to_date(sdate,'yyyy-mm-dd'),'Q')=3 m_date n_date ----------------------------------- 1 2011-09-30 2011-07-01