XMLTABLE XQuery dynamic type mismatch

I do understand why this throws this error:
ORA-19279: XPTY0004 - XQuery dynamic type mismatch: expected singleton sequence - got multi-item sequence

What I would like to get as a result is a record with a nested table column.

    SELECT x.*
      FROM XMLTABLE (
              '/batch/testload'
              PASSING xmltype (q'[<batch>
<testload>
    <Operator>IN</Operator>
    <Operator>OUT</Operator>
    <Attribute>DoorsDouble</Attribute>
</testload>
<testload>
   <Operator>IN</Operator>
   <Attribute>WindowsSingleMultiple</Attribute>
</testload>
</batch>]')
              COLUMNS operator1 VARCHAR2 (200) PATH 'Operator',
                      attribute2 VARCHAR2 (200) PATH 'Attribute') x;

Open in new window


I would like the result set to look something like the below image where Operator is a nested table column.
Desired result
I tried using COLLECT but there seems to be a type mismatch.
Thanks,
Mike
LVL 3
mmooreAsked:
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:
Now sure how you want the data returned.  You mentioned nested tables but I'm not sure.

This will return 3 rows with two columns:
    SELECT x.attribute2, o.operator
      FROM XMLTABLE (
              '/batch/testload'
              PASSING xmltype (q'[<batch>
<testload>
    <Operator>IN</Operator>
    <Operator>OUT</Operator>
    <Attribute>DoorsDouble</Attribute>
</testload>
<testload>
   <Operator>IN</Operator>
   <Attribute>WindowsSingleMultiple</Attribute>
</testload>
</batch>]')
              COLUMNS operators xmltype PATH 'Operator',
                      attribute2 VARCHAR2 (200) PATH 'Attribute') x,
xmltable('/Operator'
	passing x.operators
	columns operator varchar2(200) path '.'
) o;

Open in new window

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
mmooreAuthor Commented:
Ah, the key to it was using XMLTYPE as the datatype for operators. You also took it a step further and normalized the output. Now I can make the whole thing a sub query and have the outer query COLLECT Operator into a nested table. Thanks!
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.