Querying XMLTypes

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 ...

Get Oracle Database 11g Building Oracle XML DB Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.