我不确定为什么遇到异常错误。我还在学习PL / SQL。我试图将一些数据放入表中的游标中。然后遍历游标并将数据插入API并捕获API拒绝的记录。我可以为多个API执行一个循环吗?还有其他我不想要的东西吗?
declare
fhw UTL_FILE.FILE_TYPE;
wdir varchar2(100);
wfilename varchar2(100);
cnt number;
aidy number;
--
TYPE NextGen_rec IS RECORD(
r_pidm rprawrd.rprawrd_pidm%TYPE,
r_aidy_code rprawrd.rprawrd_aidy_code%TYPE,
r_term_code rpratrm.rpratrm_term_code%TYPE,
r_fund_code rprawrd.rprawrd_fund_code%TYPE,
r_awst_code rprawrd.rprawrd_awst_code%TYPE,
r_awst_date rprawrd.rprawrd_awst_date%TYPE,
r_accept_amt rprawrd.rprawrd_accept_amt%TYPE,
r_accept_date rprawrd.rprawrd_accept_date%TYPE,
r_offer_amt rprawrd.rprawrd_offer_amt%TYPE,
r_offer_date rprawrd.rprawrd_offer_date%TYPE,
r_data_origin rprawrd.rprawrd_data_origin%TYPE
);
--
--
TYPE cur1 IS REF CURSOR;
ng cur1;
--
Begin
--
Wdir := 'UTL_TTU_ST';
wfilename := 'ng_errors.csv';
fhw := UTL_FILE.FOPEN(wdir,wfilename,'w');
select count (*) into cnt
from ttubanr.NGAWARDLD, ttubantemp.NGAWARD
where NGAWARD_AIDY = NGAWARDLD_AIDY;
--
if cnt = 0 then
select NGAWARD_AIDY into aidy from ttubantemp.NGAWARD
where ROWNUM < 2;
--insert aid year if it doesn't exist with date from 01-01-2000 as place holder.
insert into ttubanr.NGAWARDLD
(NGAWARDLD_AIDY, NGAWARDLD_LD)
SELECT replace(replace (REPLACE (NGAWARD_AIDY, 'Academic Year ',null),'20',null),'-',null), '01-JAN-2017' FROM ttubantemp.NGAWARD;
end if;
-- Last date for aid year found
--
for award_rec in ng_rec loop
If cnt = 1 then
open ng FOR
SELECT NGAWARD_NGID,
replace(replace (REPLACE (NGAWARD_AIDY, 'Academic Year ',null),'20',null),'-',null)NGAWARD_AIDY,
CASE
WHEN NGAWARD_PERIOD = 'FALL'
THEN SUBSTR(NGAWARD_AIDY,15,4)||80
WHEN NGAWARD_PERIOD = 'SPRING'
THEN SUBSTR(NGAWARD_AIDY,20,4)||10
END NGAWARD_TERM,
(SELECT SPRIDEN_PIDM FROM SPRIDEN WHERE SPRIDEN_ID = NGAWARD_ID AND SPRIDEN_CHANGE_IND IS NULL) NGAWARD_PIDM,
NGAWARD_ID,
NGAWARD_FUND,
NGAWARD_AMT,
CASE WHEN NGAWARD_PERIOD = 'ANNUAL'
THEN 'A'
WHEN NGAWARD_PERIOD = 'FALL'
THEN 'F'
WHEN NGAWARD_PERIOD = 'SPRING'
THEN 'S'
END NGAWARD_PERIOD,
CASE WHEN NGAWARD_STATUS = 'GrantAward'
THEN 'I'
WHEN NGAWARD_STATUS = 'ModifyAward'
THEN 'U'
WHEN NGAWARD_STATUS = 'RemoveSingleSeasonAward'
THEN 'C'
WHEN NGAWARD_STATUS = 'RevokeRenewableAward'
THEN 'C'
WHEN NGAWARD_STATUS = 'DeleteAward'
THEN 'C'
END NGAWARD_STATUS,
NGAWARD_ADATE
FROM ttubantemp.NGAWARD, ttubanr.NGAWARDLD, SPRIDEN
WHERE
SPRIDEN_ID = NGAWARD_ID
AND NGAWARD_AIDY = NGAWARDLD_AIDY
and NGAWARD_ADATE > NGAWARDLD_LDATE
AND SPRIDEN_CHANGE_IND IS NULL
order by NGAWARD_ID, NGAWARD_FUND, NGAWARD_ADATE;
fetch ng into ng_rec;
End If;
--
IF ng_rec.NGAWARD_PERIOD = 'A' AND ng_rec.NGAWARD_STATUS = 'I'
THEN
rp_award.p_create(p_aidy_code => ng_rec.NGAWARD_AIDY,
p_pidm => ng_rec.NGAWARD_PIDM,
p_fund_code => ng_rec.NGAWARD_FUND,
p_awst_code => 'A',
p_awst_date => sysdate,
p_accept_amt => ng_rec.NGAWARD_AMT,
p_accept_date => sysdate,
p_offer_amt => ng_rec.NGAWARD_AMT,
p_offer_date => sysdate,
p_data_origin => 'NextGen');
--
gb_common.p_commit;
--Year award Update
ELSIF ng_rec.NGAWARD_PERIOD = 'A' AND ng_rec.NGAWARD_STATUS = 'U'
THEN
rp_award.p_update(p_aidy_code => ng_rec.NGAWARD_AIDY,
p_pidm => ng_rec.NGAWARD_PIDM,
p_fund_code => ng_rec.NGAWARD_FUND,
p_awst_code => 'A',
p_awst_date => sysdate,
p_accept_amt => ng_rec.NGAWARD_AMT,
p_accept_date => sysdate,
p_offer_amt => ng_rec.NGAWARD_AMT,
p_data_origin => 'NextGen');
--
gb_common.p_commit;
--Year award cancel
ELSIF ng_rec.NGAWARD_PERIOD = 'A' AND ng_rec.NGAWARD_STATUS = 'C'
THEN
rp_award.p_update(p_aidy_code => ng_rec.NGAWARD_AIDY,
p_pidm => ng_rec.NGAWARD_PIDM,
p_fund_code => ng_rec.NGAWARD_FUND,
p_awst_code => 'C',
p_awst_date => sysdate,
p_data_origin => 'NextGen');
--
gb_common.p_commit;
--Term award insert
ELSIF ng_rec.NGAWARD_PERIOD in ('F','S') AND ng_rec.NGAWARD_STATUS = 'I'
THEN
rp_award_schedule.p_create(p_aidy_code => ng_rec.NGAWARD_AIDY,
p_term_code => ng_rec.NGAWARD_TERM,
p_pidm => ng_rec.NGAWARD_PIDM,
p_fund_code => ng_rec.NGAWARD_FUND,
p_awst_code => 'A',
p_awst_date => sysdate,
p_accept_amt => ng_rec.NGAWARD_AMT,
p_accept_date => sysdate,
p_offer_amt => ng_rec.NGAWARD_AMT,
p_offer_date => sysdate,
p_data_origin => 'NextGen');
--
gb_common.p_commit;
--Term award update
ELSIF ng_rec.NGAWARD_PERIOD in ('F','S') AND ng_rec.NGAWARD_STATUS = 'U'
THEN
rp_award_schedule.p_update(p_aidy_code => ng_rec.NGAWARD_AIDY,
p_term_code => ng_rec.NGAWARD_TERM,
p_pidm => ng_rec.NGAWARD_PIDM,
p_fund_code => ng_rec.NGAWARD_FUND,
p_accept_amt => ng_rec.NGAWARD_AMT,
p_offer_amt => ng_rec.NGAWARD_AMT,
p_data_origin => 'NextGen');
--
gb_common.p_commit;
EXCEPTION
WHEN OTHERS THEN
gb_common.p_rollback;
IF SQLCODE = gb_event.APP_ERROR THEN
utl_file.put_line(fhw,'Rollback renumbering '||sqlerrm||','||ng_rec.NGAWARD_NGID||','||ng_rec.NGAWARD_ID||','||ng_rec.NGAWARD_AIDY||','||ng_rec.NGAWARD_TERM||','||ng_rec.NGAWARD_FUND||','||ng_rec.NGAWARD_AMT||','||ng_rec.NGAWARD_STATUS||','||ng_rec.NGAWARD_ADATE);
--
end loop;
--
end if;
--
--CLOSE ng_rec;
UTL_FILE.FCLOSE(fhw);
end;