Marc Meewis Technology Sales Consultant (marcewis@oracle) Oracle Belgium

Preview:

DESCRIPTION

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. - PowerPoint PPT Presentation

Citation preview

Marc MeewisMarc MeewisTechnology Sales ConsultantTechnology Sales Consultant(marc.meewis@oracle.com)(marc.meewis@oracle.com)

Oracle BelgiumOracle Belgium

Oracle XML DBOracle XML DBTechnical OverviewTechnical Overview

Evolution of Oracle XML Support

8i 9i R1 9i R2

Basic XML Generation andProcessing (mid-tier based)Developer Kits

DB-integrated XML StorageAnd 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

Common XML Architectures

Enforce XML Schema

Manage Content & DataUniformly

Eliminate extra movingparts

Get better performance& scalability

Make DB applicationsStandards-based

XML DB Architecture

HTTP FTP WebDAV

HTTP Client FTP Client

Content-oriented Access

Repository XMLTypeViews/Tables

WebDAV Client

Protocol Handlers

XML DBText Index Path Index Text Index B-Tree

Bitmap Index

XML DB Architecture Data-oriented Access

Oracle Net

Application ClientsJAVA Client OCI Client

JDBC/OCI

XQuery XML Schema CacheXML/DOM Parser

Repository

SQL

XMLTypeViews/Tables

9i XML DBText Index Path Index Text Index B-TreeBitmap Index

XML DB Architecture Data-oriented Access

Oracle Net

Application ClientsJAVA Client OCI Client

JDBC/OCI

XQuery XML Schema CacheXML/DOM Parser

Repository

SQL

XMLTypeViews/Tables

9i XML DBText Index Path Index Text Index B-TreeBitmap Index

Format Access

XML to Relational

XML OperatorsXML Views

XPath

XPath

Relational

Document

XML DB Architecture Data-oriented Access

Oracle Net

Application ClientsJAVA Client OCI Client

JDBC/OCI

XQuery XML Schema CacheXML/DOM Parser

Repository

SQL

XMLTypeViews/Tables

9i XML DBText Index Path Index Text Index B-TreeBitmap Index

select extractValue(value(x),'/Movie/@Title') ,extractValue(value(x),'/Movie/@RunningTime')from xml_movies xwhere existsNode(value(x),'/Movie[@Rating="R" and @RunningTime>100]') > 0/

XML DB Architecture Data-oriented Access

Oracle Net

Application ClientsJAVA Client OCI Client

JDBC/OCI

XQuery XML Schema CacheXML/DOM Parser

Repository

SQL

XMLTypeViews/Tables

9i XML DBText Index Path Index Text Index B-TreeBitmap Index

select path(1)from resource_view where under_path(res, '/demo/movie', 1) = 1/

XML DB : Storage

XMLType

Storage Implementation

CLOB Object Relational

XML DB : Storage

XMLType

Storage Implementation

CLOB Object Relational

Xpath : /

•Return contents from clob •Reassemble XML combining data structure and schema cache (tags are not stored in ds)

+ for full retrieval of XML document

XML DB : Storage

XMLType

Storage Implementation

CLOB Native (=OR)

Xpath : /a/b[c=“2”]/d

•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

XML DB Native XML Storage

Object Relational TechnologyIntroduction

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 lwhere l.order_id = o.idand 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

ID CUST_ID PO_NO LINES

Record in Orders table :

ID CUST_ID PO_NO LINES

Object - relational

ID CUST_ID PO_NO

Record in Orders table :

ID CUST_ID PO_NO LINES

PROD_ID QTY PRICE

PROD_ID QTY PRICE

PROD_ID QTY PRICE

PROD_ID QTY PRICE

Collection

Object - relational

ID CUST_ID PO_NO

select o.cust_id, l.prod_id, l.qty, l.price from orders o, table(o.lines) lwhere l.qty > 20

Record in Orders table :

ID CUST_ID PO_NO LINES

PROD_ID QTY PRICE

PROD_ID QTY PRICE

PROD_ID QTY PRICE

PROD_ID QTY PRICE

Collection

Implicit Join

XML Schema Compilation Can Be Done Automatically, or Fully/Partially Assisted

Via Schema Annotation When Schema is Used, Tables of Types are Created

AttrAttrAttrAttr

SimpleTypeSimpleTypeSimpleTypeSimpleType

ComplexTypeComplexTypeComplexTypeComplexType

Complex TypeComplex Type

ComplexTypeComplexTypeComplexTypeComplexTypeComplexTypeComplexTypeComplexTypeComplexTypeComplexTypeComplexTypeComplexTypeComplexType

AttributeAttributeAttributeAttribute

AttributeAttributeAttributeAttribute

ObjectTypeObjectTypeObjectTypeObjectType

Oracle Object TypeOracle Object Type

ComplexTypeComplexTypeComplexTypeComplexTypeComplexTypeComplexTypeComplexTypeComplexTypeCollectionTypeCollectionTypeCollectionTypeCollectionType

Oracle XML DB

DEMOFor a complete overview of the features

Oracle XML DB

Oracle & XMLOverview

XML Type XMLRepository

Summary

Data Content

Oracle XML DB

Oracle & XMLOverview

XML Type XMLRepository

Summary

Data

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

XML Type– Native datatype– methods

XML Type as column XML Type table (XML table)

XML Type • 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 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

XML Type– Native datatype– methods

XML Type as column XML Type table (XML table)

create table purchaseorder of xmltype

insert into purchaseorder values (xmltype.createxml(‘<>…</>’)

)

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

xPath XML Schema XML consistency XML integrity XML indexing XML Updating Relational Views

• 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;

XML Type

xPath XML Schema XML consistency XML integrity XML indexing XML Updating Relational Views

• 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>

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 schemaCREATE 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 checkscreate or replace trigger PURCHASEORDERVALIDATIONbefore insert on PURCHASEORDER

If (:new.PODOCUMENT.existsnode('//LineItem') > 0) THEN raise MISSING_PARTNUMBER;

end if;

...

XML Type

xPath XML Schema XML consistency XML integrity XML indexing XML Updating Relational Views

• Use FK for referential integrityalter 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>

XML Type

xPath XML Schema XML consistency XML integrity XML indexing XML Updating Relational Views

• Functional indexes xPath indexes

create unique index iPurchaseOrderReference on PurchaseOrder x (

extractValue(

value(x)

,'/PurchaseOrder/Reference‘

)

)

/

• Full text Search (Oracle Text)

XML Type

xPath XML Schema XML consistency XML integrity XML indexing XML Updating Relational Views

• 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;

XML Type

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 asselect 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 QUOTATIONfrom xml_movies x/

SQL> desc movie_info Name Null? Type ----------------------------------------- -------- ---------------------------- TITLE VARCHAR2(100) IMDBCODE NUMBER(38) RATING VARCHAR2(1) QUOTATION FLOAT(126)

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

Querying with XML as result

SQL/XML (SQLX group, www.sqlx.org)– Relational to XML

xQuery (W3C XML Query working group)– XML documents

SQL/XML

SQL/XML compliant XMLAgg XMLConcat XMLElement XMLAttributes XMLForest

Oracle Extensions XMLSequence XMLTransform ExtractValue Extract

SQL/XML

SELECT XMLElement("Department", XMLForest(deptno "DeptNo", d.dname "DeptName", d.loc

"Location")

,(SELECT XMLAGG(XMLElement("Employee",

XMLForest(e.empno "EmployeeId",

e.ename "Name",

e.job "Job",

e.mgr "Manager",

e.hiredate "Hiredate",

e.sal "Salary",

e.comm "Commission")))

FROM emp e

WHERE e.deptno = d.deptno))

FROM dept d;

SQL/XML<Department> <DeptNo>10</DeptNo> <DeptName>ACCOUNTING</DeptName> <Location>NEW YORK</Location> <Employee> <EmployeeId>7782</EmployeeId> <Name>CLARK</Name> <Job>MANAGER</Job> <Manager>7839</Manager> <Hiredate>09-JUN-81</Hiredate> <Salary>2450</Salary> </Employee> <Employee> <EmployeeId>7839</EmployeeId> <Name>KING</Name> <Job>PRESIDENT</Job> <Hiredate>17-NOV-81</Hiredate> <Salary>5000</Salary> </Employee> <Employee> <EmployeeId>7934</EmployeeId> <Name>MILLER</Name> <Job>CLERK</Job> <Manager>7782</Manager> <Hiredate>23-JAN-82</Hiredate> <Salary>1300</Salary> </Employee></Department>

XQuery

FOR $i IN sqlquery("select * from scott.emp")/ROW RETURN   <EMP empno="{$i/EMPNO}">     $i/ENAME,     $i/SALARY   </EMP>

FOR $i IN sqlquery("select * from scott.emp")/ROW,     $j IN document("dept.xml") WHERE $j/deptno = $i/DEPTNO RETURN   <EMP empno="{$i/EMPNO}" deptno="{$j/deptno}"/>

Xquery –1  // get the connection (for example, using the thick JDBC Driver)

  DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());

  Connection conn =

      DriverManager.getConnection("jdbc:oracle:@","scott","tiger");

  // create a context using that connection..

  XQueryContext ctx = new XQueryContext(conn);

  // create a string from the file

  Reader strm = new StringReader(

     "FOR $i IN sqlquery(\"select * from scott.emp\")/ROW "+

     " RETURN <EMP empno=\"{$i/EMPNO}\">$i/ENAME,$i/SALARY</EMP>");

  // prepare the query

  PreparedXQuery xq = ctx.prepareXQuery(strm);

  // get a resultset

Xquery -2

  XQueryResultSet rset = xq.executeQuery();

  while (rset.next())   {     XMLNode node = rset.getNode();  // get result nodes     System.out.println(" NODE "+ node.getNodeName());     node.print(System.out);   }

SQL/XML XQuery• XQUERY

<results> { FOR $a IN distinct(document("bib.xml")//author) RETURN <result> { $a } { FOR $b IN document("bib.xml")/bib/book[author = $a] RETURN $b/title } </result> } </results>

• SQL/XML

SELECT xmlelement("results", xmlagg(b2.column_value))

FROM (SELECT xmlelement("result",b.column_value.extract('//author'),

xmlagg(b.column_value.extract('/title')))

FROM TABLE(xmlseq(xmldocument('/bib.xml').extract('/bib/book'))) b

GROUP BY b.column_value.extract('//author')) b2

Oracle XML DB

Oracle & XMLOverview

XML Type XMLRepository

Summary

Content

XML DB - Repository

WebDAV, FTP and HTTP SQL Repository search (under_path,

depth)

select extractValue(r.res,'/Resource/DisplayName') "./purchaseOrders/1999/Apr"

from resource_view R

where under_path(r.res, 1, '/home/SCOTT/purchaseOrders/1999/Apr', 1) = 1

order by extractValue(r.res,'/Resource/DisplayName');

XML DB - Repository

Hierarchical Index– Speed up pathname resolution and folder

search– Map connect by data into folders

Navigational API (JNDI) to access objects via pathname, rename, delete and copy files

Oracle XML DB

Oracle & XMLOverview

XML Type XMLRepository

Summary

Oracle9iR2: XML DB Enhanced XMLType

– XMLSchema Support – Object-Relational Storage Maintaining DOM fidelity– XML-specific memory mgmt for better scalability and

performance Lazily loaded virtual DOM, Schema caching

– Built-in XML operators for SQL/XML interchangability– XPath Search in the server, and piecewise update of XML via

XPath– XSL Transforms in the server– Enhanced XML Views for creating your own efficient

representations of XML New XML Repository

– FTP, WebDAV, HTTP protocol servers to move XML content in and out

– ‘Foldering’ and Repository view over XML Content including access control Hierarchical Index, SQL Versioning

– SQL Repository Search

9 Benefits of XML DB XML SQL ‘duality’

– SQL operations over XML data, XML operations over SQL data Native support for XML data model

– XML Schema Constraints, other constraints, RI Storage and Structure Independence Strong data management over XML content vs. file storage Repository Functionality Multiple XML views over relational data Ease of Presentation and Interchange

– Native XSLT, built-in generation Popular API access

– DOM, SQL, PL/SQL, Java, … XML-specific performance and scalability

Recommended