我有一个包含接受数组的构造函数的类型。我想构建一个这种类型的数组并同时输入子数组。
作为一个例子
create type child as object
(
name varchar2(10)
);
/
create type children as table of child;
/
create type parent as object
(
name varchar2(10),
my_children children
);
/
create type parents as table of parent;
/
create table child_table
(
parent_name varchar2(10),
child_name varchar2(10)
);
/
create table parent_table
(
name varchar2(10)
);
/
declare
l_parents parents;
begin
select parent(p.name, (select child(c.child_name) from child_table where parent_name = p.name))
bulk collect into l_parents
from parent_table p;
end;
第四行到最后一行(select parent(p.name ....))只是伪代码,是我遇到问题的那一行。
答案 0 :(得分:0)
尝试这样的事情:
SELECT parent(p.name,
CAST((SELECT COLLECT (child(c.child_name))
FROM child_table c
WHERE parent_name = p.name
) AS children
)
)
BULK COLLECT INTO l_parents
FROM parent_table p;
答案 1 :(得分:0)
declare
l_parents parents;
begin
select parent(p.name, cast(multiset(select c.child_name from child_table c where parent_name = p.name)as children))
bulk collect into l_parents
from parent_table p;
end;