2. XML Storage Options:
1. VARCHAR2 – unstructured, limited size
2. CLOBs – unstructured, max file = 2GB
3. XMLType – structured, associate with XDK and other XML
operations
XML DB Architecture:
1. XML DB Repository
2. DOM fidelity
3. SQL* Loader
3. Using XMLTYPE
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.
4. Creating XMLType Column or table with optional
XML Schema support
create table profile(
pid number,
pfile XMLType); Declares XMLType Column
create table profile of XMLType; 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.
5.
6. Storing XML document into the database
insert into profile Insert the whole XML document in
values(100, XMLType(' SQL query
<ScholarProfile>
<ID>1</ID>
<LastName> Azzzr</LastName>
<FirstName>Hussain</FirstName>
<Email>fdsfsafafa@mail.com</Email>
<Major>Load Runner</Major>
<Grade>A</Grade>
</ScholarProfile>‘ ));
7. 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.
10. 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()
11. 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;
13. 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;
16. 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.