Binary XML Data Storage in 11g

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
  2  /
Table created.
Consider the following XML document for order transactions:
test_document.xml
<?xml version="1.0"?>
<order>
    <customer>
        <name>Customer ABC</name>
        <ccNum>1234123412341234</ccNum>
    </customer>
    <orderLines>
       <item>
        <item_id>108</item_id>
        <item_name>ORACLE 11G NEW FEATURES BOOK ED1.0</item_name>
        <quantity>1</quantity>
        <unitPrice>$38.00</unitPrice>
      </item>
      <item>
        <item_id>109</item_id>
        <item_name>ORACLE TUNING GUIDE ED1.0</item_name>
        <quantity>1</quantity>
        <unitPrice>$22.00</unitPrice>
      </item>
   </orderLines>
   <receipt>
        <subtotal>$60.00</subtotal>
        <salesTax>$4.80</salesTax>
        <total>$64.80</total>
   </receipt>
</order>
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.  
SELECT
   extractValue(value(b),'/order/customer/name')  customer_name,
   extractValue(value(d),'/item/item_id')  item_id,
   extractValue(value(d),'/item/quantity')  quantity,
   extractValue(value(d),'/item/unitPrice')  unit_price,
   extractValue(value(b),'/order/receipt/subtotal')  subtotal,
   extractValue(value(b),'/order/receipt/salesTax')  salesTax,
   extractValue(value(b),'/order/receipt/total')  total
from
BINARY_XML_TABLE a
,TABLE(XMLSequence(Extract(object_value,'/order'))) b
,TABLE(XMLSequence(Extract(value(b),'/order/orderLines'))) c
,TABLE(XMLSequence(Extract(value(c),'/orderLines/item'))) d;
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.

 

参考至:http://www.dba-oracle.com/t_11g_new_binary_xlm_storage.htm

如有错误,欢迎指正

邮箱:[email protected]

你可能感兴趣的:(binary)