XML Storage Options

1. 2. 3.

VARCHAR2 – unstructured, limited size CLOBs – unstructured, max file = 2GB XMLType – structured, associate with XDK and other XML operations

XML DB Architecture:
1. 2.


XML DB Repository DOM fidelity SQL* Loader

XML Piecewise Update
Update part of the xml document in the database specified by the XPath expression.

XML Schema Validation

Manually or automatically validate XML documents as they are inserted to the Database.

XML Document Generation

Generate XML data from database using normal SQL query.

Creating XMLType Column or table with optional XML Schema support
create table profile( pid number, pfile XMLType); create table profile of XMLType;

Declares XMLType Column Declares XMLType Table Not Recommended

create table profile of XMLType XMLSCHEMA “http://bumbus.ucdavis.edu/scholar.xsd” ELEMENT “UCLEADS” Declares XMLType Table conformed to an XML Schema and specific the root element of the xml document to be inserted.

Storing XML document into the database
Insert the whole XML document in insert into profile SQL query values(100, XMLType(' <ScholarProfile> <ID>1</ID> <LastName> Azzzr</LastName> <FirstName>Hussain</FirstName> <Email>fdsfsafafa@mail.com</Email> <Major>Load Runner</Major> <Grade>A</Grade> </ScholarProfile>„ ));

Accessing XML data stored as XMLType instance
1. ExtractValue() - access the value of an XML node 2. ExistsNode() - check if a particular node existed 3. Exact() - extract a collection of XML nodes

4. XMLSequence() - converts a fragment of XML into a collection (a table) of XMLType instances.

SELECT extract(X.pfile,'UCLEADS/ScholarProfile/Major') FROM profile X;

Results are returned as a fragment of XML

SELECT extractValue(value(w),'/Major') FROM profile X, TABLE ( xmlsequence ( extract(value(X), '/UCLEADS/ScholarProfile/Major'))) w;

Values are extracted from the nodes of the XMLType table generated using the XMLSequence()

SELECT existsNode(x.pfile, '/UCLEADS/ScholarProfile/Major') SubFound, existsNode(x.pfile, '/UCLEADS/ScholarProfile[Major="ORACLE"]') MajorFound, existsNode(x.pfile, '/UCLEADS/ScholarProfile[Major="Oracle"]') MajorFound2 FROM Profile1 X;

SELECT count(*) FROM Profile X WHERE existsNode(x.pfile, '/UCLEADS/ScholarProfile[Major="Oracle"„]) = 1;


UPDATEXML takes as arguments an XMLType instance and an XPath-value pair and returns an XMLType instance with the updated value

SELECT UPDATEXML(emp_col, '/EMPLOYEES/EMP[EMPNAME="Joe"]/SALARY/text()', 100000, '//EMP[EMPNAME="Jack"]/EMPNAME/text()','Jackson', '//EMP[EMPNO=217]', XMLTYPE.CREATEXML('<EMP><EMPNO>217</EMPNO><EMPNAME>Jane< /EMPNAME>')) FROM emp_tab e;



UPDATEXML(emp_col, '/EMPLOYEES/EMP/SALARY/text()', 0) emp_view_col

FROM emp_tab e

XML Piecewise Update

UPDATE profile t SET value(t) = updateXML(value(t),'/UCLEADS/ScholarProfile/Major/text()','CS') WHERE existsNode(value(t), '/UCLEADS/ScholarProfile[Major="Computer Science"]') = 1; • isFragment() – returns (1) if the XMLType contains XML document fragment. • getClobVal() – converts the XMLType document into CLOB object. • getRootElement() – get the root element of the XML document. • getNameSpace() – get the namespace of the root element of the XML document.

select xmltype(xmltype.getclobVal(t.pfile)).getRootElement() Exmpl1, xmltype.getRootElement(t.pfile)Exmp2, xmltype.isFragment(t.pfile)isFrag1 , xmltype.isFragment(extract(t.pfile,'/UCLEADS/ScholarProfile'))isFrag2 from profile1 t;


Sign up to vote on this title
UsefulNot useful