XQuery in Oracle

Querying a node value from an XML data that is saved in Clob field.

Step 1: First we need to convert the Clob field into xml using the function xmltype(clob field).

Step 2: use the extractvalue function to apply the XQuery providing an Xpath.

Example:
<Order>
 <OrderID>22223832</OrderID>
 <ClientID>45091</ClientID>
 <Total>22222</Total>
        <OrderDate>2009-04-05</OrderDate>
</Order>

– gets the ClientID for the Order
SELECT extractvalue(xmltype(dataField), ‘//Order/ClientID’) from Logs

more on extractvalue :

http://www.dba-oracle.com/t_extractvalue_and_datatype_errors.htm

Posted by admin on Mar 10 2009 in Oracle