How to use dbms_output to display an array of values assigned to a variable?

gcbm1984 picture gcbm1984 · Oct 29, 2014 · Viewed 8.9k times · Source

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;

Answer

Jon Heller picture Jon Heller · Oct 30, 2014

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;
/