DB2 Scalar functions - XMLTABLE
The XMLTABLE function returns a result table from the evaluation of XQuery expressions, possibly using specified input arguments as XQuery variables. Each sequence item in the result sequence of the row XQuery expression represents a row of the result table.
The schema is SYSIBM. The function name cannot be specified as a qualified name.
If xmlnamespaces-declaration is not specified, only the pre-established set of statically known namespaces apply to the the XQuery expressions.
This clause has no impact on how non-XML values are passed. The non-XML values create a new copy of the value during the cast to XML.
If the evaluation of any of the XQuery expressions results in an error, then the XMLTABLE function returns the XQuery error (SQLSTATE class '10').
List as a table result the purchase order items for orders with a status of 'NEW'.
SELECT U."PO ID" , U."Part #" , U."Product Name" , U."Quantity" , U."Price" , U."Order Date" FROM PURCHASEORDER P, XMLTABLE('$po/PurchaseOrder/item' PASSING P.PORDER AS "po" COLUMNS "PO ID" INTEGER PATH '../@PoNum', "Part #" CHAR(10) PATH 'partid', "Product Name" VARCHAR(50) PATH 'name', "Quantity" INTEGER PATH 'quantity', "Price" DECIMAL(9,2) PATH 'price', "Order Date" DATE PATH '../@OrderDate' ) AS U WHERE P.STATUS = 'Unshipped'