0

I have something like this, but got an error says ORA-06533: Subscript beyond count. I want to see all the values from the "select distinct" statement in the output tab. Anyone can help? thanks!

DECLARE
   TYPE v_chks_array IS VARRAY (10) OF VARCHAR2 (50);

   arrSRCs   v_chks_array;
BEGIN
   arrSRCs := v_chks_array ();
   arrSRCs.EXTEND (10);

   SELECT /*+parallel (a,4)*/
         DISTINCT a.src_table
     BULK COLLECT INTO arrSRCs
     FROM hcr_dm.hcr_dm_fact a;

   DBMS_OUTPUT.put_line (arrSRCs (10));
END;
Jon Heller
  • 34,999
  • 6
  • 74
  • 132
gcbm1984
  • 53
  • 1
  • 4
  • 9

2 Answers2

1

Collections are not needed here:

begin
    for results in
    (
        select /*+ parallel (a,4) */ distinct a.src_table
        from hcr_dm.hcr_dm_fact a;
    ) loop
        dbms_output.put_line(results.src_table);
    end loop;
end;
/
Jon Heller
  • 34,999
  • 6
  • 74
  • 132
0

Instead of VARRAY, you may try a TABLE type collection. You'll have more flexibility with number of records to hold while doing BULK COLLECT.

Create or replace type v_chks_array IS TABLE OF VARCHAR2 (500);

More information can be found at http://docs.oracle.com/cd/B19306_01/appdev.102/b14261/collections.htm

Ram Dwivedi
  • 470
  • 3
  • 11