What's the difference bet. xmlforest and xmlagg?

Hello,

By definition, it says that xmlforest Creates XML elements from columns, using the name of each column as the name of the corresponding element while xmlagg Combines a collection of rows, each containing a single XML value, to create a single value containing an XML forest.

I know one pertains to cols and the other to rows but it's still confusing. So when do you use xmlforest and and when do you use xmlagg?

Thanks!
bluepaintAsked:
Who is Participating?
 
slightwv (䄆 Netminder) Commented:
I was slightly off when typing from memory.

Like it says xmlagg is an aggregator of fragments/nodes.

Check out the small test case below.
drop table tab1 purge;
create table tab1(col1 number, col2 char(1));
insert into tab1 values(1,'a');
insert into tab1 values(2,'b');
commit;

--returns two rows
select xmlforest(col1, col2) from tab1;

--aggregates/joins the two rows above into a single fragment
select xmlagg(xmlforest(col1, col2)) from tab1;

--that allows you to create a single xmldocument from the rows
select xmlelement("MyXMLDoc",xmlagg(xmlforest(col1, col2))) from tab1;

Open in new window

0
 
slightwv (䄆 Netminder) Commented:
They say what they do.

Xmlforest collects acorss columns: select col1, col2 col3 from table;

The result lumps the columns together.

Xmlagg collects across rows: select col1 from table;

The result lumps the rows together.

The docs have examples that show the differences.

You use them when you need the different calls.
0
 
bluepaintAuthor Commented:
I see, thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.