oracle 如何初始化 {TABLE}%ROWTYPE 的 varray 表?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4122469/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to initialize a varray table of {TABLE}%ROWTYPE?
提问by dr jerry
I have a varray defined like:
我有一个 varray 定义如下:
declare
TYPE tnr_l IS VARRAY(30) of lve%ROWTYPE;
I want this varray to be initialized with a fetch from the database:
我希望通过从数据库中获取来初始化这个 varray:
select * into tnr_l from lve where type = 'TNR' order by value;
But this fails with:
但这失败了:
.ORA-06550: line 6, column 23:
PLS-00321: expression 'TNR_L' is inappropriate as the left hand side of an
assignment statement
How can I make this work?
我怎样才能使这项工作?
回答by Tony Andrews
You need to declare a variable of the type tnr_l, and then you need to use bulk collect
in the select like this example:
你需要声明一个tnr_l类型的变量,然后你需要bulk collect
像这个例子一样在select中使用:
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;