Chapter 5. Processing XML with PL/SQL

PL/SQL is Oracle’s procedural language extension to SQL, and is the database programming language familiar to nearly all Oracle DBAs and application developers. In this chapter, we’ll study lots of examples that illustrate how to perform basic XML processing using PL/SQL. In particular, we’ll learn how to:

  • Load external XML files into the database

  • Parse XML using the Oracle XML Parser for PL/SQL

  • Search XML documents in memory using XPath expressions

  • Post an XML message to another server and get an XML response back

  • Enqueue and dequeue XML messages from Oracle Advanced Queuing (AQ) queues

In addition, in this chapter we’ll cover the basic mechanics of producing XML automatically from SQL queries and transforming the results into any desired XML format using XSLT stylesheets. Both of these topics are covered in full in their own chapters later in the book. For an abbreviated overview of PL/SQL itself, see Chapter 10.

Along the way, we’ll build up several useful PL/SQL packages that you can use to simplify basic XML processing from within your own PL/SQL stored procedures, functions, packages, and database triggers. The full source code for these XML helper packages appears in Appendix A, and is available on the O’Reilly web site. Let’s dive right in.

Loading External XML Files

When a developer is setting out to store the contents of an XML document in the database to perform queries over its content and structure, one of the first questions that arises ...

Get Building Oracle XML 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.