Skip Headers
Oracle® Database SQL Language Reference
11g Release 1 (11.1)

Part Number B28286-01
Go to Documentation Home
Go to Book List
Book List
Go to Table of Contents
Go to Index
Go to Master Index
Master Index
Go to Feedback page
Contact Us

Go to previous page
Go to next page
View PDF



Description of extractvalue.gif follows
Description of the illustration extractvalue.gif

The EXTRACTVALUE function takes as arguments an XMLType instance and an XPath expression and returns a scalar value of the resultant node. The result must be a single node and be either a text node, attribute, or element. If the result is an element, then the element must have a single text node as its child, and it is this value that the function returns. You can specify an absolute XPath_string with an initial slash or a relative XPath_string by omitting the initial slash. If you omit the initial slash, the context of the relative path defaults to the root node.

If the specified XPath points to a node with more than one child, or if the node pointed to has a non-text node child, then Oracle returns an error. The optional namespace_string must resolve to a VARCHAR2 value that specifies a default mapping or namespace mapping for prefixes, which Oracle uses when evaluating the XPath expression(s).

For documents based on XML schemas, if Oracle can infer the type of the return value, then a scalar value of the appropriate type is returned. Otherwise, the result is of type VARCHAR2. For documents that are not based on XML schemas, the return type is always VARCHAR2.


The following example takes as input the same arguments as the example for EXTRACT (XML). Instead of returning an XML fragment, as does the EXTRACT function, it returns the scalar value of the XML fragment:

SELECT warehouse_name, 
   EXTRACTVALUE(e.warehouse_spec, '/Warehouse/Docks')
   FROM warehouses e 
   WHERE warehouse_spec IS NOT NULL;

-------------------- ------------
Southlake, Texas     2
San Francisco        1
New Jersey
Seattle, Washington  3