660 likes | 855 Views
Oracle XML DB Technical Overview. Marc Meewis Technology Sales Consultant (marc.meewis@oracle.com) Oracle Belgium. Evolution of Oracle XML Support. 8 i. 9 i R1. 9 i R2. Basic XML Generation and Processing (mid-tier based) Developer Kits. DB-integrated XML Storage And Retrieval.
E N D
Oracle XML DB Technical Overview Marc Meewis Technology Sales Consultant(marc.meewis@oracle.com) Oracle Belgium
Evolution of Oracle XML Support 8i 9i R1 9i R2 Basic XML Generation and Processing (mid-tier based) Developer Kits DB-integrated XML Storage And Retrieval Native XML DB
What is Oracle XML DB? • High Performance storage and retrieval technologie part of Oracle 9i R2 and + • W3C XML data model in Oracle Server • Standard access methods for querying and navigating XML
Why XML in the Database • Enforce and leverage the XML data model • Loosely coupled, flexible applications • XML Schema, DOM • Enable richer semantics and better management for content-oriented applications • Store as XML vs. Files or LOBs • Queryability, Integrity, etc. • Process XML close to data for high scalability and performance • Generation, Transformation • Superior memory management for large XML
Why XML in the Database (Contd.) • Reduce maintenance costs of extra moving parts • Eliminate separate ‘XML-processing’ layers • Keep applications standards-based • W3C, IETF, ANSI/ISO, J2EE • Eliminate proprietary file formats, message formats, delimited columns
Get better performance & scalability Enforce XML Schema Manage Content & Data Uniformly Eliminate extra moving parts Make DB applications Standards-based Common XML Architectures
Protocol Handlers B-Tree Bitmap Index Text Index XML DB Architecture Content-oriented Access HTTP Client FTP Client WebDAV Client HTTP WebDAV FTP XMLType Views/Tables Repository XML DB Text Index Path Index
JAVA Client OCI Client XML/DOM Parser XQuery XML Schema Cache SQL XMLType Views/Tables Repository 9i XML DB B-TreeBitmap Index Text Index Path Index Text Index XML DB Architecture Data-oriented Access Application Clients JDBC/OCI Oracle Net
JAVA Client OCI Client XML/DOM Parser XQuery XML Schema Cache SQL XMLType Views/Tables Repository 9i XML DB B-TreeBitmap Index Text Index Path Index Text Index XML DB Architecture Data-oriented Access Access Format Application Clients XML Operators XML Views XPath Relational JDBC/OCI XML to Relational Document Oracle Net XPath
JAVA Client OCI Client XML/DOM Parser XQuery XML Schema Cache SQL XMLType Views/Tables Repository 9i XML DB B-TreeBitmap Index Text Index Path Index Text Index XML DB Architecture Data-oriented Access select extractValue(value(x),'/Movie/@Title') ,extractValue(value(x),'/Movie/@RunningTime') from xml_movies x where existsNode(value(x),'/Movie[@Rating="R" and @RunningTime>100]') > 0 / Application Clients JDBC/OCI Oracle Net
JAVA Client OCI Client XML/DOM Parser XQuery XML Schema Cache SQL XMLType Views/Tables Repository 9i XML DB B-TreeBitmap Index Text Index Path Index Text Index XML DB Architecture Data-oriented Access Application Clients select path(1) from resource_view where under_path(res, '/demo/movie', 1) = 1 / JDBC/OCI Oracle Net
XML DB : Storage XMLType CLOB Object Relational Storage Implementation
XML DB : Storage Xpath : / XMLType • Return contents from clob • Reassemble XML combining data structure and schema cache (tags are not stored in ds) + for full retrieval of XML document CLOB Object Relational Storage Implementation
XML DB : Storage Xpath : /a/b[c=“2”]/d XMLType • Read XML document from clob • Parse Document (create DOM) • Resolve xPath • Return result • Rewrite xPath to SQL • Return Result + very fast for all partial manipulation, no DOM involved - resource consuming CLOB Native (=OR) Storage Implementation
XML DB Native XML Storage Object Relational Technology Introduction
Object - relational • Order (1) / Orderlines (M) : 2 relational tables • Order(id, cust_id, po_no) • Orderlines (id, order_id, prod_id, qty) select o.cust_id, l.prod_id, l.qty, l.price from orders o, orderlines l where l.order_id = o.id and l.qty > 20
Object - relational • OR: • OrderlineType (UDT) • Prod_id integer • Qty float • Price float • Order (Object relational table) • Id number • Cust_id number • Po_no number • Lines nested table of OrderlineType
Object - relational Record in Orders table : ID CUST_ID PO_NO LINES ID CUST_ID PO_NO LINES
ID CUST_ID PO_NO LINES Object - relational Collection Record in Orders table : ID CUST_ID PO_NO PROD_ID QTY PRICE PROD_ID QTY PRICE PROD_ID QTY PRICE PROD_ID QTY PRICE
ID CUST_ID PO_NO LINES Object - relational Collection Record in Orders table : ID CUST_ID PO_NO PROD_ID QTY PRICE PROD_ID QTY PRICE PROD_ID QTY PRICE PROD_ID QTY PRICE Implicit Join select o.cust_id, l.prod_id, l.qty, l.price from orders o, table(o.lines) l where l.qty > 20
Complex Type Oracle Object Type Attr Attribute SimpleType Attribute ComplexType ObjectType ComplexType ComplexType ComplexType ComplexType ComplexType CollectionType XML Schema Compilation • Can Be Done Automatically, or Fully/Partially Assisted Via Schema Annotation • When Schema is Used, Tables of Types are Created
Oracle and XML : More info? • OTN: • XML Technology centerhttp://otn.oracle.com/tech/xml/index.html • XML DBhttp://otn.oracle.com/tech/xml/xmldb/index.html
Oracle XML DB DEMO For a complete overview of the features
Oracle XML DB Data Content XML Type XML Repository Summary Oracle & XML Overview
Oracle XML DB Data XML Type XML Repository Summary Oracle & XML Overview
Oracle XML DB • XML Type (data management) • XML Repository (content management)
XML DB XML Type
XML Type • XML Type • Native datatype • methods • XML Type as column • XML Type table
XML Type • XML Type • Native datatype • methods • XML Type as column • XML Type table
createXML • extract • existsNode • isFragment • getClobVal • getStringVal • getNumberVal • transform • toObject • isSchemabased • getSchemaURL • getRootElement • getNameSpace • schemaValidate • isSchemaValidated XML Type • XML Type • Native datatype • methods • XML Type as column • XML Type table (XML table)
XML Type • XML Type • Native datatype • methods • XML Type as column • XML Type table
XML Type • XML Type • Native datatype • methods • XML Type as column • XML Type table create table purchaseorder ( id integer ,data xmltype ) insert into purchaseorder values ( 1 ,xmltype.createXML(‘<>… </>’) )
XML Type • XML Type • Native datatype • methods • XML Type as column • XML Type table (XML table)
XML Type create table purchaseorder of xmltype insert into purchaseorder values ( xmltype.createxml(‘<>…</>’) ) • XML Type • Native datatype • methods • XML Type as column • XML Type table (XML table)
XML Type • XML Type • Native datatype • methods • XML Type as column • XML Type table (XML table) Creating XMLType Instances • Literal Docs or Fragments from String or CLOB • xmltype('<foo bar="3"/>') • From a File • xmltype(getDocument('AmericanBeauty.xml')) • From a URL or Stream • Using HTTPUriType and Methods on It • From Scratch Using DOM API • Via dbms_xmldom Package or Java API
XML Type • xPath • XML Schema • XML consistency • XML integrity • XML indexing • XML Updating • Relational Views
XML Type • Full xPath support • SQL select count(*) from purchaseorder x where existsNode( value(x),'/PurchaseOrder[User="SMITH"]‘ ) = 1; Select extractValue( value(x),'/PurchaseOrder/Reference‘ ) from purchaseorder x where existsNode( value(x), '/PurchaseOrder/LineItems/ LineItem/Part[@Id="037429139523"]‘ ) = 1; • xPath • XML Schema • XML consistency • XML integrity • XML indexing • XML Updating • Relational Views
XML Type • Full xPath support • DB URI http://…/oradb/schema/table/row/xpath http://…/oradb/scott/emp/row[ename=“KING”] http://…/oradb/scott/emp/row[ename=“KING”]?transform <?xml version="1.0"?> <ROW> <EMPNO>7839</EMPNO> <ENAME>KING</ENAME> <JOB>PRESIDENT</JOB> <HIREDATE>17-NOV-81</HIREDATE> <SAL>5000</SAL> <DEPTNO>10</DEPTNO> </ROW> • xPath • XML Schema • XML consistency • XML integrity • XML indexing • XML Updating • Relational Views
XML Type • xPath • XML Schema • XML consistency • XML integrity • XML indexing • XML Updating • Relational Views • Register XML schema dbms_xmlschema.registeruri( 'http://www.oracle.com/xdb/orderSchema.xsd’,'/home/SCOTT/xsd/puchaseOrder.xsd' ); • Constrain XMLType to schema CREATE TABLE xmlorder ( info XMLTYPE )XMLSCHEMA 'http://www.oracle.com/xdb/orderSchema.xsd‘ELEMENT 'PurchaseOrder‘ /
XML Type • xPath • XML Schema • XML consistency • XML integrity • XML indexing • XML Updating • Relational Views • Storage • CLOB (White Space fidelity) • Object Relational (DOM fidelity) (annotations) • XMLType : abstracts storage details
XML Type • xPath • XML Schema • XML consistency • XML integrity • XML indexing • XML Updating • Relational Views • Use triggers for full or partial checks • create or replace trigger PURCHASEORDERVALIDATIONbefore insert on PURCHASEORDER • If (:new.PODOCUMENT.existsnode('//LineItem') > 0) THEN raise MISSING_PARTNUMBER; • end if; • ...
XML Type • Use FK for referential integrity • alter table xdb_departments • add constraint IS_VALID_LOCATION • foreign key (xmldata."Location" ) references locations • / • <Department id="93" name="Labtest3"> • <Location>Diegem</Location> • <Employees> • <Employee empno="310" name="Peter"> • <Job>MANAGER</Job> • xPath • XML Schema • XML consistency • XML integrity • XML indexing • XML Updating • Relational Views
XML Type • Functional indexes • xPath indexes • create unique index iPurchaseOrderReference on PurchaseOrder x ( • extractValue( • value(x) • ,'/PurchaseOrder/Reference‘ • ) • ) • / • Full text Search (Oracle Text) • xPath • XML Schema • XML consistency • XML integrity • XML indexing • XML Updating • Relational Views
XML Type • Partial update of XML data update purchaseorder p set value(p) = updateXml( value(p) ,'/PurchaseOrder/User/text()‘ ,'DRAKE‘ )where existsNode( value(p), '/PurchaseOrder/Actions/Action[position()=1 and User="VISHU"]‘ ) = 1; • xPath • XML Schema • XML consistency • XML integrity • XML indexing • XML Updating • Relational Views
xml_movies = xmltype table : schema related = object relational storage create or replace view movie_info as select extractValue(value(x),'/Movie/@Title') as TITLE ,extractValue(value(x),'/Movie/@imdbCode') as IMDBCODE ,extractValue(value(x),'/Movie/@rating') as RATING ,extractValue(value(x),'/Movie/Review/@quotation') AS QUOTATION from xml_movies x / SQL> desc movie_info Name Null? Type ----------------------------------------- -------- ---------------------------- TITLE VARCHAR2(100) IMDBCODE NUMBER(38) RATING VARCHAR2(1) QUOTATION FLOAT(126) XML Type • xPath • XML Schema • XML consistency • XML integrity • XML indexing • XML Updating • Relational Views
XML DB – XMLType • XSL-T • XML Views (relational to XMLType) • Memory Management (lazy loaded virtual DOM) • Schema cache • Programming model • Client side JDBC/OCI, Javabeans • Server side Java, PL/SQL