create or replace procedure prc_yanglaolixi is
str_aac001 varchar2(16);
str2_aac001 varchar2(16);
num_aic410 number(12,2);
num_aic412 number(12,2);
num_aic413 number(12,2);
str_aae045 varchar2(6);
interest_year number;
sum_money number(12,2);
total_money number(12,2);
cur_time varchar2(50);
CURSOR CUR_AAC001 IS
SELECT DISTINCT AAC001 FROM IC40 ;
cursor cur_lixi is
select aac001,aae045,aic410,aic412,aic413 from ic40 where aac001=str_aac001;
begin
--删除数据
execute immediate 'truncate table v1_yanglao_zhye';
cur_time:=to_char(sysdate,'yyyymm');
open cur_aac001;
loop
fetch cur_aac001 into str_aac001;
-- sum_money:=0;
total_money:=0;
exit when CUR_AAC001%notfound;
open cur_lixi;
loop
fetch cur_lixi into str2_aac001,str_aae045,num_aic410,num_aic412,num_aic413; --日期类型错误?
exit when cur_lixi%notfound;
sum_money:=num_aic410+num_aic412+num_aic413;
while to_date(str_aae045,'yyyymm')
loop
select aia001 into interest_year from aa03
where aae001=case
when to_number(substr(str_aae045,1,4))>=7 then to_number(substr(str_aae045,1,4))
else to_number(substr(str_aae045,1,4))-1 end;
sum_money:=sum_money*(1+interest_year/12);
str_aae045:=to_char(add_months(to_date(str_aae045,'yyyymm'),1),'yyyymm');
end loop;
total_money:=total_money+sum_money;
end loop;
close cur_lixi;
insert into v1_yanglao_zhye select t2.AAC001 ,t2.AAB001 ,t2.AAC003 ,t2.aac004 ,t2.akc020 ,t2.AAC002 ,
total_money ,count(aae003) ,max(aae003) from ic40 t1,ac01 t2 where t2.AAC001=t1.aac001
and t2.aac001=str_aac001
group by t2.AAC001,t2.AAC003,t2.aac004,t2.AAB001,t2.akc020,t2.AAC002 ;
commit;
end loop;
close CUR_AAC001;
--aa03.aia001养老记账利率
end prc_yanglaolixi;