Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>DB2 has decent support for XML data, so you have a few options on how to shred XML and apply it to one or more tables.</p> <p>The function you're looking for is <a href="http://publib.boulder.ibm.com/infocenter/db2luw/v9r7/topic/com.ibm.db2.luw.xml.doc/doc/c0023903.html" rel="nofollow">XMLTABLE</a>. It is by far the most flexible way to shred XML into a single tabular result set.</p> <p>When your incoming XML document contains data that needs to go to multiple tables, the <a href="http://publib.boulder.ibm.com/infocenter/db2luw/v9r7/topic/com.ibm.db2.luw.admin.cmd.doc/doc/r0022721.html" rel="nofollow">DECOMPOSE XML DOCUMENT</a> statement is powerful, but it requires a pre-registered XML Schema Document with special annotations that dictate the mapping of each XML node to its relational target. This statement doesn't allow a <a href="http://publib.boulder.ibm.com/infocenter/db2luw/v9r7/topic/com.ibm.db2.luw.sql.ref.doc/doc/r0003272.html" rel="nofollow">declared global temporary table</a> (DGTT) to serve as a target table, which has been a problem when the incoming XML data requires additional processing in a staging DGTT before it can be written to its final destination.</p> <p>As for your cursor-based approach to apply the shredded data, you could replace the entire loop with a single <a href="http://publib.boulder.ibm.com/infocenter/db2luw/v9r7/topic/com.ibm.db2.luw.sql.ref.doc/doc/r0010873.html" rel="nofollow">MERGE</a> statement that uses the XMLTABLE result set for the input expression. There are a lot of examples online of using DB2's MERGE statement for "upsert" processing, in which each incoming row could require an INSERT or an UPDATE depending the presence or absence of that primary key in the destination table.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload