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

dr *_*rry 2 oracle plsql initialization varray ora-06550

我有一个varray定义如下:

declare
    TYPE tnr_l IS VARRAY(30) of lve%ROWTYPE;
Run Code Online (Sandbox Code Playgroud)

我希望使用数据库中的fetch初始化此varray:

select * into tnr_l from lve where type = 'TNR' order by value;
Run Code Online (Sandbox Code Playgroud)

但这失败了:

.ORA-06550: line 6, column 23:
PLS-00321: expression 'TNR_L' is inappropriate as the left hand side of an
assignment statement
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?

Ton*_*ews 8

你需要声明一个类型为tnr_l的变量,然后你需要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;
Run Code Online (Sandbox Code Playgroud)