Is it possible to do a select directly into a hierarchical user type?
Imagine a table structure like this:
PARENT
------
ID
NAME
CHILD
-----
ID
PARENT_ID
NAME
Additionally, I have user types like this:
create or replace type child_item as object
(
ID NUMBER(10),
NAME VARCHAR(255)
);
create or replace type children_table as table of child_item;
create or replace type parent_item as object
(
ID NUMBER(10),
NAME VARCHAR(255),
CHILDREN CHILDREN_TABLE
);
create or replace type parent_table as table of parent_item;
And a statement like this:
select * from parent p inner join child c on p.id = c.parent_id;
Now, I want the result of that statement to be in an object of type parent_table. Is this somehow possible without the use of a complex FOR loop?
You can use COLLECT:
This will return a list of
PARENT_ITEMthat you can BULK COLLECT into aPARENT_TABLE.You could use COLLECT again in an outer query to get a PARENT_TABLE directly: