Purpose
XMLSEQUENCE() converts an XML document into a varray of XML elements. The function returns each element in the XML document as a row to form a collection of XML elements.
Syntax
XMLSEQUENCE( XMLType_instance)
Note
The XMLSEQUENCE() function cannot be used in a SELECT clause.
Parameters
| Parameter | Description |
|---|---|
| XMLType_instance | An XMLType instance that serves as the input to the function. |
Return type
The return type is XMLType collection.
Examples
Call the XMLSEQUENCE() and EXTRACT() functions to extract the specified nodes in the target XML document, which is the <Videogame> node and its child nodes. The XPath expression is /Videogame/*, which specifies to extract the <Videogame> node and all its child nodes. The XMLSEQUENCE() function returns the extracted nodes as part of the table. Call the TABLE() function to convert the returned result into a queryable table. The query result uses rownum as the row number and uses the extracted node values as values in the returned column_value column.
SELECT rownum, column_value
FROM TABLE(
XMLSEQUENCE(
extract(
XMLtype('<Videogame>
<Type>Racing</Type>
<Name>NFS Most Wanted</Name>
<Version>2.0</Version>
<Size>5.5 GB</Size>
</Videogame>'),
'/Videogame/*'
)
)
);
The return result is as follows:
+--------+-------------------------------+
| ROWNUM | COLUMN_VALUE |
+--------+-------------------------------+
| 1 | <Type>Racing</Type> |
| 2 | <Name>NFS Most Wanted</Name> |
| 3 | <Version>2.0</Version> |
| 4 | <Size>5.5 GB</Size> |
+--------+-------------------------------+
4 rows in set