日期:2014-05-17 浏览次数:21043 次
SELECT add_months(ADD_MONTHS(DATE'2010-12-01',LEVEL)+19,-1) AS COL1
FROM DUAL
CONNECT BY LEVEL <= 12
COL1
--------------------------
1 2010/12/20
2 2011/1/20
3 2011/2/20
4 2011/3/20
5 2011/4/20
6 2011/5/20
7 2011/6/20
8 2011/7/20
9 2011/8/20
10 2011/9/20
11 2011/10/20
12 2011/11/20
定义一个计算上个月的函数
create or replace function F_Pre_month(pi_yearmonth in varchar2) return varchar2 is
Result varchar2(6);
year number;
month number;
begin
year:=to_number(pi_yearmonth,1,4);
month:=to_number(pi_yearmonth,5,2);
month:=month-1;
if(month<=0) then
month:=12;
year:=year-1;
end if;
Result:=year
------解决方案--------------------
lpad(to_char(month),2,'0');
return(Result);
end F_Pre_month;
然后
select
2012
------解决方案--------------------
lpad(to_char(rownum),2,'0') 月份,
F_Pre_month(2012
------解决方案--------------------
lpad(to_char(rownum),2,'0'))
------解决方案--------------------
'20' 起始日期,
2012
------解决方案--------------------
lpad(to_char(rownum),2,'0')
------解决方案--------------------
'21' 结束日期
from dual connect by rownum<=12
可以算出每个月的起始和结束日期
其他的就好处理了