Team Fly | ![]() ![]() |
The extract() function is similar to the existsnode() function. The extract() function extracts the node or a set of nodes from the document identified by the XPath expression and returns an XMLType instance containing an XML fragment. The extracted nodes can be elements, attributes, or text nodes. When extracted out, all text nodes are collapsed into a single text node value.
The extractvalue() function takes as arguments an XMLType instance and an XPath expression. It returns a scalar value corresponding to the result of the XPath evaluation on the XMLType instance. The extractvalue() tries to infer the proper return type from the XML schema of the document. If the XMLType is non-schema-based or the proper return type cannot be determined, Oracle XML DB returns a varchar2.
Let's have a look now at our SQL query, and then pick apart the text in Table 8-3.
1- select extractvalue(p.PO_FILE, 'PurchaseOrder/ShippingInstructions/address') 2- from PURCHASE_ORDER p 3- where existsnode(p.PO_FILE,'/PurchaseOrder/User = ''SHAUNA"') = 1
The following is the expected result of our preceding SQL query:
EXTRACTVALUE(P.PO_FILE,'PURCHASEORDER/SHIPPINGINSTRUCTIONS/ADDRESS') -------------------------------------------------------------------------------- 249 Kracqueric Ave. Ottawa ON K1A 1A1 Canada
Team Fly | ![]() ![]() |