1
4

1 に答える 1

1

Your problem is that the variable in a cursor loop is always a tabletype based on the cursor definition. You need to specify which field from the table you want to add to the array:

v_owner_internal_id(MyRowPositionInVarray) := d_owner_internal_id.d_owner_internal_id;

Similarly, the rest of your assignments will need to be changed as well:

v_internal_id(MyRowPositionInVarray) := d_owner_internal_id.d_internal_id;

Obviously, it would be a good idea to change the variable used by the cursor loop to something less confusing.


You could also simplify this a little by using the cursor to define an array:

TYPE t_rst1 IS VARRAY(500) OF cur_rst1%rowtype;
v_rst1 t_rst1 := t_rst1();
...
for r_rst1 in cur_rst1 loop
...
v_rst1(MyRowPositionInVarray) := r_rst1;
...
dbms_output.put_line(v_rst1(i).d_owner_internal_id || ',  ' ||  
                     v_rst1(i).d_internal_id || ',  ' ||  
                     v_rst1(i).d_tid || ',  ' ||  
                     v_rst1(i).d_entity_name || ',  ' ||  
                     v_rst1(i).d_form_seq); 

Finally, you could simplify this vastly by using bulk collect:

DECLARE
  MyTID varchar2(10); 
CURSOR Cursor_rst1 IS
       SELECT d_owner_internal_id,
              d_internal_id,
              d_tid,
              d_entity_name,
              d_form_seq
         FROM rtns.itas_rtn_ct_1120_cor tblRecords
        WHERE d_form_seq = '2710' --Tax Year =2003
          AND D_TID = MyTID;  
  TYPE t_rst1 IS table OF Cursor_rst1%rowtype; 
  r_rst1 t_rst1;

  BEGIN  
  MyTID := '0000083';  

  open Cursor_rst1;
  fetch Cursor_rst1 bulk collect into r_rst1;
  close Cursor_rst1;

  FOR i IN r_rst1.first .. r_rst1.last LOOP
       dbms_output.put_line(r_rst1(i).d_owner_internal_id || ',  ' ||  
                            r_rst1(i).d_internal_id || ',  ' ||  
                            r_rst1(i).d_tid || ',  ' ||  
                            r_rst1(i).d_entity_name || ',  ' ||  
                            r_rst1(i).d_form_seq);  
  END LOOP;  
END;
于 2012-09-06T18:30:13.743 に答える