PL / SQL游标

时间:2019-07-12 14:37:54

标签: loops for-loop plsql cursor

此处的plsql中的新手..数据库低于oracle8。

具有此表格(下面的结构),其中包含会员的每月汇款。每个成员可以每月修改其汇款;自动将最新标记的(FlagInd)标记为'A';他们之前提交的“ I” ...每笔交易都会获得一个新交易编号(transNo)

会员编号

transNo号

汇款截止日期

DateFiled日期(实际报告日期)

RemittanceAmt号码

FlagInd varchar2(A或I)

报告格式应为:

MemberId Jan Feb Feb Apr .... Dec

创建了两(2)个独立的游标;第一个让特定会员汇款达特定年份的公司;第二个将其最新的每月汇款标记为“ A”。

以下我的一些代码;我正在使用utl工具将输出写入文件:

declare

cursor c1 is
select distinct memberId mId
from table1
where to_char(remittanceMo, 'yyyy' )  = '2018';
v_memberId c1%rowtype;

cursor c2 (i_memberId in number) is
select max(datefiled) dtfiled, 
max(transno) transnum, 
sum(nvl(remittanceamt, 0)) amt
from table1
where memberid = i_memberid
and flagInd ='A' ;
v_remit_mo1 c2%rowtype;
v_remit_mo2 c2%rowtype;
. 
. 
v_remit_mo12 c2%rowtype;

begin

for v_memberId in c1
loop
open c2 (v_memberId.mId);
fetch c2 into v_remit_mo1;
close c2;

and so on until the 12th month.. 

end loop;

end;

我的问题是,还检索了那些标记为“ I”的交易。我不知道为什么,当第二个游标说每月只应检索标记为“ A”的最新记录时。.请帮助。

0 个答案:

没有答案
相关问题