Is there any way to cast the XMLTYPE returned by XMLTable as a full document, instead of a node?
Well, the error message is pretty clear : you're trying to insert fragments, not a document (single-rooted content). It is not allowed.
I guess the query returns multiple INVT_DATA elements, right?
SQL> INSERT INTO book_master
7 PASSING xmltype('<BOOKS><INVT_DATA/><INVT_DATA/></BOOKS>')
9 invt_data XMLTYPE PATH 'INVT_DATA'
10 ) t;
INSERT INTO book_master
ERROR at line 1:
ORA-19010: Cannot insert XML fragments
You have to build a document by wrapping the returned fragments into a single root element.
You are correct that the structure looks like:
However, if I run just the SELECT query, without the insert, I do get single-rooted elements, which should be legal. It is as if the internal datatype is node instead of document, and I'm wondering if I can cast it.