Struggling with trying to get XML into a database? Recently DataDirect was asked: What is the easiest solution to bulk insert XML data into a flat structure table in an Oracle database? and ...
The need for saving XML files to a database is quite common since XML data can be found everywhere; and DataDirect XQuery has an easy and highly scalable solution for doing just that. Scalability and performance always depends on many factors, for example; how is the data structured in the XML document(s), for example; how does it need to be shred into columns, maybe into multiple tables; what kind of "massage" data needs to go through, and so on. But in general, users can rely on the DataDirect XQuery streaming and projection capabilities to boost scalability and on its ability to work efficiently with relational data sources to leverage performance. In this tutorial we'll show you several examples of how to store XML file in database tables.
Consider the following hypothetical scenario: your warehouse receives daily shipments of books; details about the books are available in XML documents structured like this:
Real shipment lists are actually made of hundreds of thousands of entries. The SQL database used by your warehouse has a "shipments" table which is defined like this:
You can write an XQuery loading all the data in the XML document into the "shipments" table quite easily, relying on the DataDirect XQuery RDBMS update capabilities:
Of course there may be cases in which the data been inserted in the database needs to be somewhat modified; for example, support the "TITLE" columns requires all capital case letters:
...or maybe something a little bit more interesting: suppose the @quantity attribute in the input XML document is optional, and if it's missing it means quantity is actually 1:
Or perhaps the single XML needs to be shred in multiple tables, for example doing something like this:
DataDirect XQuery is able to run these XQueries that save XML into a database in a streaming fashion; so, users will be able to upload millions of records without scalability issues. Yet another way in which DataDirect XQuery helps you bridge the XML and SQL worlds in a highly scalable and performant way. If you need to import, load or save XML into a database, download a free trial today!