Fetching a single column with dynamic query

107 views Asked by At

I want to fetch a single column into an array. I am using following code

TYPE t_column IS TABLE OF TABLE_1.COLUMN_1%TYPE INDEX BY PLS_INTEGER;
ar_column t_column;

Then the query is something like

select column_1 from table_1 where column_1 = values;

And i am trying to fetch it

OPEN cr_table FOR select_query;
LOOP
    FETCH cr_table INTO ar_column LIMIT 1000;
    EXIT WHEN ar_column.count = 0
END LOOP;

But for this i am getting error Error(1526,25): PLS-00597: expression 'ar_column' in the INTO list is of wrong type

1

There are 1 answers

0
Ashish sinha On

try this:

declare

cursor c1 is

select last_name ls from empc;

type x is table of employees.last_name%type;

x1 x := x();

cnt integer :=0;

begin

for z in c1 loop 

cnt := cnt +1;

exit when cnt > 5;

x1.extend;

x1(cnt) := z.ls;

dbms_output.put_line(cnt || ' '|| x1(cnt));

end loop;

end;