'arrays in pl sql | varray | associative

I'm planning to write a pl sql pseudo code procedure a gets all records from emp and is passed to procedure b procedure b getting called inside from a , is transforming the data from emp , each emp record is traversed 6 times and storing the data in an array inside procedure b , i used varray (size of 2000 to 2 mil) and also associative array , but it is always failing after handling 10 -15 records .i.e. after handling it for 60 -90 records

i am reusing the same index for storing my data but nothing worked i.e. 1 to 6

I am not sure what i am doing wrong , please assist .

create or replace PROCEDURE query_emp  ( bill_cycle_ip in number,
                                                    no_of_recs in number ) AS
    TYPE billAcnt IS REF CURSOR RETURN emp%ROWTYPE;
    ba_rec emp%ROWTYPE;
    b_a billAcnt;
    total_num_of_rec number ;
BEGIN
       OPEN b_a FOR 
            select * from 
               (select * from emp where bill_cycle =1 and ban_status in ('O'  ,'S')
               union 
               select * from   emp where bill_cycle =1 and ban_status in ('N')
               and STATUS_LAST_DATE  >= sysdate -30 
               )
               where ban not in (Select ban from temp_ba)
               and rownum <no_of_recs;
       LOOP
             FETCH b_a INTO ba_rec;
                EXIT WHEN b_a%NOTFOUND;
              create_final_snapshot (ba_rec); 
        END LOOP;
   CLOSE b_a;
END;


create or replace procedure create_final_snapshot  ( ba_rec IN emp%ROWTYPE ) AS 
   cur_bl_seq_number number ; 
   bl_seq_number_minus_six number ; 
    type total_due_amt is table of number INDEX BY PLS_INTEGER  ;
    nt total_due_amt := total_due_amt();
    b number := 1 ;
  BEGIN
            cur_bl_seq_number :=ba_rec.BL_CUR_BILL_SEQ_NO ;
                      if ba_rec.BL_CUR_BILL_SEQ_NO-5  <=1  then 
                      bl_seq_number_minus_six:=1;
                      else 
                      bl_seq_number_minus_six:=ba_rec.BL_CUR_BILL_SEQ_NO-5;
                      end if ;
                            for a in  bl_seq_number_minus_six..cur_bl_seq_number 
                            LOOP
                                     --nt.extend();
                                     select xyz into nt(b)    from emp_2 where  ban =ba_rec.ban and bill_seq_no =a ;
                                     dbms_output.put_line('total_due_amt_list sun= ' ||ba_rec.ban ||' ' || nt(b) || ' bill seq no ' ||a  ||' b ' || b );
                                     b := b +1; 
                            END loop;
                           b:=1;
        insert into temp_ba 
       values (nt(1) ,nt(2),       nt(3),nt(4),nt(5),nt(6)   ); 
 END;


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source