SlideShare a Scribd company logo
Oracle XML Handling
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
   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.
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.
Oracle XML Handling
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>‘ ));
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
Oracle XML Handling
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;
<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>
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;
<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>
CREATE VIEW new_emp_view
AS
SELECT


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;
azharpro@gmail.com

More Related Content

What's hot (20)

PPT
Sequences and indexes
Balqees Al.Mubarak
 
PPT
MySql slides (ppt)
webhostingguy
 
PPT
My sql with querys
NIRMAL FELIX
 
PPTX
Introduction to database
Pongsakorn U-chupala
 
PPT
MYSQL - PHP Database Connectivity
V.V.Vanniaperumal College for Women
 
PPTX
Mysql
lotlot
 
PDF
4.3 MySQL + PHP
Jalpesh Vasa
 
PPTX
FYBSC IT Web Programming Unit V Advanced PHP and MySQL
Arti Parab Academics
 
PDF
Powerful Explain in MySQL 5.6
MYXPLAIN
 
PDF
lab56_db
tutorialsruby
 
PDF
MySQL for beginners
Saeid Zebardast
 
PDF
Introduction to php database connectivity
baabtra.com - No. 1 supplier of quality freshers
 
PPSX
ASP.Net Presentation Part2
Neeraj Mathur
 
PPT
Lecture6 display data by okello erick
okelloerick
 
PPTX
Database Connectivity in PHP
Taha Malampatti
 
PPTX
Java class 8
Edureka!
 
PPT
Sqlxml vs xquery
Amol Pujari
 
PPTX
Oracle views
Balqees Al.Mubarak
 
Sequences and indexes
Balqees Al.Mubarak
 
MySql slides (ppt)
webhostingguy
 
My sql with querys
NIRMAL FELIX
 
Introduction to database
Pongsakorn U-chupala
 
MYSQL - PHP Database Connectivity
V.V.Vanniaperumal College for Women
 
Mysql
lotlot
 
4.3 MySQL + PHP
Jalpesh Vasa
 
FYBSC IT Web Programming Unit V Advanced PHP and MySQL
Arti Parab Academics
 
Powerful Explain in MySQL 5.6
MYXPLAIN
 
lab56_db
tutorialsruby
 
MySQL for beginners
Saeid Zebardast
 
Introduction to php database connectivity
baabtra.com - No. 1 supplier of quality freshers
 
ASP.Net Presentation Part2
Neeraj Mathur
 
Lecture6 display data by okello erick
okelloerick
 
Database Connectivity in PHP
Taha Malampatti
 
Java class 8
Edureka!
 
Sqlxml vs xquery
Amol Pujari
 
Oracle views
Balqees Al.Mubarak
 

Similar to Oracle XML Handling (20)

PPT
Sql2005 Xml
jason hu 金良胡
 
PPT
DB2 Native XML
Amol Pujari
 
PPTX
SQLPASS AD501-M XQuery MRys
Michael Rys
 
DOCX
Xml generation and extraction using XMLDB
pallavi kasibhotla
 
PPTX
Hotsos 2013 - Creating Structure in Unstructured Data
Marco Gralike
 
PPTX
OakTable World 2015 - Using XMLType content with the Oracle In-Memory Column...
Marco Gralike
 
PPT
XMLLec1 (1xML lecturefsfsdfsdfdsfdsfsdfsdfdsf
Kamrankhan925215
 
PPT
XMLLec1.pptsfsfsafasfasdfasfdsadfdsfdf dfdsfds
Kamrankhan925215
 
PPT
XML stands for EXtensible Markup Language
NetajiGandi1
 
PPTX
Sql2005 xml
nkaluva
 
PDF
PostgreSQL and XML
Peter Eisentraut
 
PPTX
OPP2010 (Brussels) - Programming with XML in PL/SQL - Part 2
Marco Gralike
 
PDF
Session06 handling xml data
kendyhuu
 
PPS
Ado.net session14
Niit Care
 
PDF
XML Support: Specifications and Development
Peter Eisentraut
 
PPTX
Design Concepts For Xml Applications That Will Perform
Marco Gralike
 
PPTX
Oracle Database 11g Release 2 - XMLDB New Features
Marco Gralike
 
PPTX
Miracle Open World 2011 - XML Index Strategies
Marco Gralike
 
PPTX
Xml and databases
Raghu nath
 
PPTX
OPP2010 (Brussels) - Programming with XML in PL/SQL - Part 1
Marco Gralike
 
Sql2005 Xml
jason hu 金良胡
 
DB2 Native XML
Amol Pujari
 
SQLPASS AD501-M XQuery MRys
Michael Rys
 
Xml generation and extraction using XMLDB
pallavi kasibhotla
 
Hotsos 2013 - Creating Structure in Unstructured Data
Marco Gralike
 
OakTable World 2015 - Using XMLType content with the Oracle In-Memory Column...
Marco Gralike
 
XMLLec1 (1xML lecturefsfsdfsdfdsfdsfsdfsdfdsf
Kamrankhan925215
 
XMLLec1.pptsfsfsafasfasdfasfdsadfdsfdf dfdsfds
Kamrankhan925215
 
XML stands for EXtensible Markup Language
NetajiGandi1
 
Sql2005 xml
nkaluva
 
PostgreSQL and XML
Peter Eisentraut
 
OPP2010 (Brussels) - Programming with XML in PL/SQL - Part 2
Marco Gralike
 
Session06 handling xml data
kendyhuu
 
Ado.net session14
Niit Care
 
XML Support: Specifications and Development
Peter Eisentraut
 
Design Concepts For Xml Applications That Will Perform
Marco Gralike
 
Oracle Database 11g Release 2 - XMLDB New Features
Marco Gralike
 
Miracle Open World 2011 - XML Index Strategies
Marco Gralike
 
Xml and databases
Raghu nath
 
OPP2010 (Brussels) - Programming with XML in PL/SQL - Part 1
Marco Gralike
 
Ad

Recently uploaded (20)

PPTX
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
PPTX
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
PPTX
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
PDF
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
PPTX
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
PDF
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
PDF
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
PPTX
Post Dated Cheque(PDC) Management in Odoo 18
Celine George
 
PPTX
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
PDF
Horarios de distribución de agua en julio
pegazohn1978
 
PPTX
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
PPTX
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
PDF
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
PPTX
QUARTER 1 WEEK 2 PLOT, POV AND CONFLICTS
KynaParas
 
PDF
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
PDF
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
PPTX
HUMAN RESOURCE MANAGEMENT: RECRUITMENT, SELECTION, PLACEMENT, DEPLOYMENT, TRA...
PRADEEP ABOTHU
 
PPTX
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
PPTX
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
PDF
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
Post Dated Cheque(PDC) Management in Odoo 18
Celine George
 
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
Horarios de distribución de agua en julio
pegazohn1978
 
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
QUARTER 1 WEEK 2 PLOT, POV AND CONFLICTS
KynaParas
 
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
HUMAN RESOURCE MANAGEMENT: RECRUITMENT, SELECTION, PLACEMENT, DEPLOYMENT, TRA...
PRADEEP ABOTHU
 
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
Ad

Oracle XML Handling

  • 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.
  • 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>[email protected]</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.
  • 8. SELECT extract(X.pfile,'UCLEADS/ScholarProfile/Major') FROM profile X; Results are returned as a fragment of XML
  • 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;
  • 12. <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>
  • 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;
  • 14. <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>
  • 15. CREATE VIEW new_emp_view AS SELECT UPDATEXML(emp_col, '/EMPLOYEES/EMP/SALARY/text()', 0) emp_view_col 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.
  • 17. 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;