Oracle 11g New Features Tips
In previous versions of Oracle, two Extensible Markup Language (XML) storage options were available: unstructured, or CLOB, and storage and structured, or schema-based. In Oracle 11g, binary XML has been added as a new storage option.
Unstructured storage treats an XML document as a large object and stores the file in the database without being aware of the content. This option has the best insertion and deletion performance, but the worst relational access and consumption of disk space.
Structured storage requires prior registration of the XML schema and inserts an XML document into an object-relational structure. This storage option has the best query performance and disk space consumption, but the highest cost during initial insertion. This high cost is caused because during insertion, the document is shredded and stored into database objects created during the registration of the XML schema.
Binary XML, the new storage option introduced in 11g, stores the document in a post-parse binary format designed specifically for XML. This option will likely be the best choice for most XML requirements. The additional binary storage offers insertion performance comparable to unstructured storage, yet query and disk space performance that is comparable to structured storage. Unlike structured storage, the benefits of binary XML are not dependent on schema registration. This is due to the option of registering a binary XML schema to have schema based binary XML tables. However, one limitation remains in that a registered XML schema cannot be shared between a binary XML and object relational table.
The best strategy when choosing how to manage XML content is to first try the binary storage option and evaluate whether the performance is acceptable. If the relational access performance is not acceptable, then try the structured storage option. The reason that binary storage is preferred is that it is easy to use and requires the least amount of maintenance because schema registration is not required. Binary XML type columns are also easier to use in non-XMLType tables since performance is not dependent on the creation of indexes.
To use binary storage, the XML table must be created with the following syntax:
SQL> CREATE TABLE BINARY_XML_TABLE OF XMLType XMLTYPE STORE AS BINARY XML
Consider the following XML document for order transactions:
<item_name>ORACLE 11G NEW FEATURES BOOK ED1.0</item_name>
<item_name>ORACLE TUNING GUIDE ED1.0</item_name>
Insert this document into the binary XML table using the following syntax:
SQL> insert into BINARY_XML_TABLE values (XMLTYPE(BFILENAME ('XML_DIR','test_document.xml'),nls_charset_id('AL32UTF8')));
1 row created.
After insertion, the document is immediately available for relational access.
CUSTOMER_NAME ITEM_ID QUANTITY UNIT_PRICE SUBTOTAL SALESTAX TOTAL
-------------- ------- -------- ---------- -------- -------- ------
Customer ABC 108 1 $38.00 $60.00 $4.80 $64.80
Customer ABC 109 1 $22.00 $60.00 $4.80 $64.80
As demonstrated above, the syntax for relational access to a binary XML table does not change from other storage options.