使用动态查询获取单个列

时间:2014-01-08 22:45:49

标签: sql oracle plsql bulk-collect

我想将一个列提取到一个数组中。我正在使用以下代码

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

然后查询类似

select column_1 from table_1 where column_1 = values;

我正在尝试取它

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

但为此我收到错误Error(1526,25): PLS-00597: expression 'ar_column' in the INTO list is of wrong type

1 个答案:

答案 0 :(得分:0)

试试这个:

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;