Using XML in a declared temporary table
Starting from DB2 9.7, we can create declared temporary tables with XML columns in them. DGTTs can contain XML data and they can be used just like regular tables.
How to do it...
Let's see how we can create a declared temporary table with an XML columns:
1. Create a declared temporary table with XML column in it:
DECLARE GLOBAL TEMPORARY TABLE sample_xml (empno INT, sal_rise_date DATE, sal_dtls XML) ON COMMIT DELETE ROWS NOT LOGGED IN user_temp_tbsp;
2. Insert an XML document in the temporary table. To do that, use the
XMLPARSE
function. This function converts a serialized string value to an XML document. In case of any errors in the XML document, an error is returned:INSERT INTO SESSION.sample_xml VALUES(1007, CURRENT DATE, XMLPARSE(document'<salary_revision sal_dtl_key = "5099"> <old_salary> <monthly_salary>30000</monthly_salary> <effective_date>24-11-2010</effective_date> </old_salary> <new_salary>...