如何初始化{TABLE}%ROWTYPE的varray表?

时间:2010-11-08 09:11:39

标签: oracle plsql initialization ora-06550 varray

我的varray定义如下:

declare
    TYPE tnr_l IS VARRAY(30) of lve%ROWTYPE;

我希望通过数据库中的提取来初始化此varray:

select * into tnr_l from lve where type = 'TNR' order by value;

但这失败了:

.ORA-06550: line 6, column 23:
PLS-00321: expression 'TNR_L' is inappropriate as the left hand side of an
assignment statement

我该如何做到这一点?

1 个答案:

答案 0 :(得分:8)

您需要声明类型为tnr_l的变量,然后您需要在select中使用bulk collect,如下例所示:

declare
  type t_dept is varray(100) of dept%rowtype;
  l_dept t_dept;
begin
  select * bulk collect into l_dept from dept;
  for i in 1..l_dept.count loop
    dbms_output.put_line(l_dept(i).dname);
  end loop;
end;