XMLTABLE advantages
In certain situations, XQuery expression results are easier to process if they are in a table than if they are in a sequence.
Returning a table instead of a sequence enables the following operations
to be performed from within an SQL query context:
- Iteration over results of an XQuery expression
from within an SQL fullselect For example, in the following query, the SQL fullselect iterates over the table that results from executing the XQuery expression //customerinfo in XMLTABLE.
SELECT X.* FROM CUSTOMER, XMLTABLE (XMLNAMESPACES(DEFAULT 'http://posample.org'), '//customerinfo' PASSING CUSTOMER.INFO COLUMNS "CUSTNAME" VARCHAR(30) PATH 'name', "CITY" VARCHAR(30) PATH 'addr/city') X
- Insertion of values from stored XML documents into tables
This technique is a simple form of decomposition, where decomposition is the process of storing fragments of an XML document in columns of relational tables.
- Individual processing of items in a sequence
If you return the items in a sequence as a single row, with each item in a separate column, it is easier to process the individual items.
- Sorting on values from an XML documentFor example, in the following query, results are sorted by the customer names that are stored in XML documents in the INFO column of the CUSTOMER table.
SELECT X.* FROM CUSTOMER, XMLTABLE (XMLNAMESPACES(DEFAULT 'http://posample.org'), '//customerinfo' PASSING CUSTOMER.INFO COLUMNS "CUSTNAME" VARCHAR(30) PATH 'name', "CITY" VARCHAR(30) PATH 'addr/city') X ORDER BY X.CUSTNAME
- Storing of some XML values as relational and some values as XML