Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
The best way to query XMLTypes in Oracle Database 11g is to use XQuery. We will discuss XQuery further in Chapter 8. Here let’s learn from a simple example on how to extract the first_ name from a contact (query_xmltype_xsxtbl.sql):
Listing 2-12 Query XMLType Using XQuery
SELECT XMLQuery(‘declare namespace ns=“http://xmlbook.com/sample/contact.xsd”;/ns:contact/ns:first_name’
PASSING c.object_value RETURNING CONTENT) result
from contact_xsxtbl c;
RESULT
------------------------------------------------------------------------------
<first_name xmlns=“http://xmlbook.com/sample/contact.xsd”>John</first_name>
In this example, we first need to declare the namespace and then use the namespace to specify the qualified XML element name in XPath.