Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

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 name in XPath.


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial