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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bluepaintAuthor Commented:
I see, thanks!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.