XML Storage Options:1.   VARCHAR2 – unstructured, limited size2.   CLOBs – unstructured, max file = 2GB3.   XMLType – stru...
   Using XMLTYPE   XML Piecewise Update    Update part of the xml document in the database specified by the    XPath exp...
Creating XMLType Column or table with optional XML Schema supportcreate table profile(         pid number,         pfile X...
Storing XML document into the databaseinsert into profile                 Insert the whole XML document invalues(100, XMLT...
Accessing XML data stored as XMLType instance1. ExtractValue()   - access the value of an XML node2. ExistsNode()   - chec...
SELECT extract(X.pfile,UCLEADS/ScholarProfile/Major)FROM profile X;                                                   Resu...
SELECT extractValue(value(w),/Major) FROM profile X, TABLE ( xmlsequence (          extract(value(X),          /UCLEADS/Sc...
SELECT   existsNode(x.pfile, /UCLEADS/ScholarProfile/Major) SubFound,   existsNode(x.pfile, /UCLEADS/ScholarProfile[Major=...
<EMPLOYEES>    <EMP>        <EMPNO>112</EMPNO>        <EMPNAME>Joe</EMPNAME>        <SALARY>50000</SALARY>    </EMP>    <E...
UPDATEXML takes as arguments an XMLType instance and an XPath-value pair andreturns an XMLType instance with the updated v...
<EMPLOYEES>    <EMP>                         <EMPLOYEES>        <EMPNO>112</EMPNO>        <EMP>        <EMPNAME>Joe</EMPNA...
CREATE VIEW new_emp_viewASSELECTUPDATEXML(emp_col, /EMPLOYEES/EMP/SALARY/text(), 0) emp_view_colFROM emp_tab e
XML Piecewise UpdateUPDATE profile t SET value(t) = updateXML(value(t),/UCLEADS/ScholarProfile/Major/text(),CS) WHERE exis...
select     xmltype(xmltype.getclobVal(t.pfile)).getRootElement() Exmpl1,    xmltype.getRootElement(t.pfile)Exmp2,     xmlt...
azharpro@gmail.com
Oracle XML Handling
Oracle XML Handling
Oracle XML Handling
Upcoming SlideShare
Loading in …5
×

Oracle XML Handling

792 views

Published on

XML handling in Oracle database 10g

Published in: Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
792
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
17
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Oracle XML Handling

  1. 1. XML Storage Options:1. VARCHAR2 – unstructured, limited size2. CLOBs – unstructured, max file = 2GB3. XMLType – structured, associate with XDK and other XML operationsXML DB Architecture:1. XML DB Repository2. DOM fidelity3. SQL* Loader
  2. 2.  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.
  3. 3. Creating XMLType Column or table with optional XML Schema supportcreate table profile( pid number, pfile XMLType); Declares XMLType Columncreate table profile of XMLType; Declares XMLType Table Not Recommendedcreate 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.
  4. 4. Storing XML document into the databaseinsert into profile Insert the whole XML document invalues(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>‘ ));
  5. 5. Accessing XML data stored as XMLType instance1. ExtractValue() - access the value of an XML node2. ExistsNode() - check if a particular node existed3. Exact() - extract a collection of XML nodes4. XMLSequence() - converts a fragment of XML into a collection (a table) of XMLType instances.
  6. 6. SELECT extract(X.pfile,UCLEADS/ScholarProfile/Major)FROM profile X; Results are returned as a fragment of XML
  7. 7. 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()
  8. 8. 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;
  9. 9. <EMPLOYEES> <EMP> <EMPNO>112</EMPNO> <EMPNAME>Joe</EMPNAME> <SALARY>50000</SALARY> </EMP> <EMP> <EMPNO>217</EMPNO> <EMPNAME>Jane</EMPNAME> <SALARY>60000</SALARY> </EMP> <EMP> <EMPNO>412</EMPNO> <EMPNAME>Jack</EMPNAME> <SALARY>40000</SALARY> </EMP></EMPLOYEES>
  10. 10. UPDATEXML takes as arguments an XMLType instance and an XPath-value pair andreturns an XMLType instance with the updated valueSELECT 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;
  11. 11. <EMPLOYEES> <EMP> <EMPLOYEES> <EMPNO>112</EMPNO> <EMP> <EMPNAME>Joe</EMPNAME> <EMPNO>112</EMPNO> <SALARY>50000</SALARY> <EMPNAME>Joe</EMPNAME> </EMP> <SALARY>100000</SALARY> </EMP> <EMP> <EMP> <EMPNO>217</EMPNO> <EMPNO>217</EMPNO> <EMPNAME>Jane</EMPNAME> <EMPNAME>Jane</EMPNAME> <SALARY>60000</SALARY> </EMP> </EMP> <EMP> <EMP> <EMPNO>412</EMPNO> <EMPNO>412</EMPNO> <EMPNAME>Jackson</EMPNAME> <SALARY>40000</SALARY> <EMPNAME>Jack</EMPNAME> </EMP> <SALARY>40000</SALARY> </EMPLOYEES> </EMP></EMPLOYEES>
  12. 12. CREATE VIEW new_emp_viewASSELECTUPDATEXML(emp_col, /EMPLOYEES/EMP/SALARY/text(), 0) emp_view_colFROM emp_tab e
  13. 13. XML Piecewise UpdateUPDATE 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.
  14. 14. 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;
  15. 15. azharpro@gmail.com

×