Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

extracting XML with xmltable

Erik_NLJul 20 2012 — edited Jul 20 2012
Since i recently got a comment here on OTN that extract/extractvalue shouldn't be used anymore to extract XML I've been playing around with xmltable.
I'm however running into a small problem.

I try to extract a very simple piece of xml in this way:
SELECT d.*
  FROM (SELECT xmltype ('<ArrayOfstring>
                           <string>415391</string>
                           <string>415392</string>
                      </ArrayOfstring>
')
                  x
          FROM DUAL),
       XMLTABLE ('$d/ArrayOfstring'
                 PASSING x AS "d"
                 COLUMNS string VARCHAR2 (100) PATH 'string') d;
and I get this error: XPTY0004 - XQuery dynamic type mismatch: expected singleton sequence - got multi-item sequence

I don't quite get what's going wrong, since the same code does work with a more complex pieve of xml:
SELECT d.*
  FROM (SELECT xmltype ('<ArrayOfProperties>
                        <Properties>
                            <Id>98247</Id>
                            <code>001</code>
                            <name>4 Megapixel</name>
                        </Properties>
                        <Properties>
                            <Id>98248</Id>
                            <code>001</code>
                            <name>5 Megapixel</name>
                        </Properties>
                    </ArrayOfProperties>') x FROM DUAL),
       XMLTABLE (
          '$d/ArrayOfProperties/Properties'
          PASSING x AS "d"
          COLUMNS Id VARCHAR2 (100) PATH 'Id',
                  Naam VARCHAR2 (4000) PATH 'name',
                  code VARCHAR2 (100) PATH 'code') d                 
Edited by: Erik_NL on 20-jul-2012 6:11
This post has been answered by Dom Brooks on Jul 20 2012
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 17 2012
Added on Jul 20 2012
3 comments
385 views