I am getting a ORA-06532 error in my pl/sql procedure. It has to do with my array, and it seems to be happening on the line that starts: “term_1 := …”. The query that selects into gets 7 records, so it should be the same amount as what I am calling for. I am a little new to the SQL array thing, so I may have missed something obvious. Any help is appreciated, thanks.
DECLARE
listOfTerms VC50_ARRAY;
term_1 varchar2(30);
term_2 varchar2(30);
term_3 varchar2(30);
term_4 varchar2(30);
term_5 varchar2(30);
term_6 varchar2(30);
term_7 varchar2(30);
BEGIN
SELECT apl.awdp_acad_terms
BULK COLLECT INTO listOfTerms
FROM fa_years fay
JOIN award_periods_ls apl
ON apl.award_periods_id = fay.award_periods_id
WHERE (SELECT b.awdp_fa_year as faYear
FROM award_periods_ls a
JOIN coll18_test.fa_years b ON a.award_periods_id = b.award_periods_id
WHERE awdp_acad_terms = v_ug_term) = fay.awdp_fa_year
ORDER BY apl.awdp_acad_terms DESC;
term_1 := listOFTerms(1);
term_2 := listOFTerms(2);
term_3 := listOFTerms(3);
term_4 := listOFTerms(4);
term_5 := listOFTerms(5);
term_6 := listOFTerms(6);
term_7 := listOFTerms(7);
I think you’re over-complicating this. You code is equivalent to:
You can then reference the items in your type by their index values so
term_1is the same ast_listofterms(1). There’s no need create an additional variable with the same value; you can reference it in the same way solength(term1)andlength(t_listofterms(1))are also the same.There’s a lot of stuff out there about array processing but PSOUG is helpful as is the documentation.
Judging by your comment you may be referencing the collection explicitly, i.e.
something := t_listofterms(7). This assumes that there is a specific number of rows.Bulk collectfills a collection from 1 to n, where n is the number of rows returned by the query. It’s often better to loop through this if you want to do something with it rather than explicit referencing. Something like,