Purpose
This function converts the content of an XML document into a VARRAY containing XML elements. It returns each element of the XML document as a row, forming a collection of XML elements.
Syntax
XMLSEQUENCE( XMLType_instance)
Note
The XMLSEQUENCE function cannot be used in the SELECT clause.
Parameters
| Field | Description |
|---|---|
| XMLType_instance | This parameter is an instance of the XML type, which serves as the input to the function. |
Return type
Returns an XMLType collection.
Examples
Use the XMLSEQUENCE function and the EXTRACT function to extract specified nodes from the target XML. In this example, the target XML fragment is the <Videogame> node and its subnodes; the XPath expression is /Videogame/*, which indicates that all subnodes under the <Videogame> node should be extracted; the XMLSEQUENCE function returns the extracted nodes as part of a table; and the TABLE function converts it into a queryable table. The query results use ROWNUM as the row number and return the extracted node values as values in the 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
