用ORCL建一个日历表。要求:入参只有一个(年),区分闰年和平年。输入年份,得到12个月,以及每一天的数据。字段名:ID,年,月,日。
------解决思路----------------------
假设传入的参数为P_Year,VARCHAR2类型
create table T AS
select ID,P_YEAR AS 年,TO_CHAR(A,'MM') AS 月,TO_CHAR(A,'DD') AS 日
from(
select ROWNUM ID,TO_DATE(P_YEAR
------解决思路----------------------
'-01-01','YYYY-MM-DD')+ROWNUM-1 AS A from DUAL
CONNECT BY TO_CHAR(TO_DATE(P_YEAR
------解决思路----------------------
'-01-01','YYYY-MM-DD')+ROWNUM-1,'YYYY')=P_Year
)
------解决思路----------------------
create table daysbiao(
days varchar2(10),
Month1 varchar2(10),
years varchar2(10),
MONTHID varchar2(20)
);
create or replace procedure Days_insert(in_years varchar2
)
is
begin
declare
x number;
y number;
c_days number;
begin
x:=0;
while x<=11 loop
x:=x+1;
SELECT to_char(LAST_DAY(to_date('2000'
------解决思路----------------------
'-'
------解决思路----------------------
x,'yyyy-mm')),'dd') into c_days FROM dual;
y:=0;
while y<c_days loop
y:=y+1;
insert into daysbiao(dayid,years,month1,days) values (se_years.nextval,in_years,x,y);
end loop;
end loop;
end;
commit;
exception
when others
then
rollback;
end ;
begin
days_insert('2000');
end;