Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Here is an example oI how XMLTable() can be used in Oracle Database 10g Release 2.
SELECT description
FROM tab_xmldata ,
xmltable('/PurchaseOrder/LineItems/LineItem/Description' passing xml_data
columns
description varchar2(64) path '/')
Code sample below demonstrates how we can create XML1ype iews.
SET ECHO ON
CREATE OR REPLACE VIEW purchaseorder_header_xml AS
SELECT id
,EXTRACTVALUE(xml_data, '/PurchaseOrder/Reference') reference
,EXTRACTVALUE(xml_data, '/PurchaseOrder/Requestor') requestor
,EXTRACTVALUE(xml_data, '/PurchaseOrder/User') po_user
,EXTRACTVALUE(xml_data, '/PurchaseOrder/CostCenter') costcenter
,EXTRACTVALUE(xml_data, '/PurchaseOrder/SpecialInstructions') spl_instructions
FROM tab_xmldata
/
CREATE OR REPLACE VIEW purchaseorder_header
AS SELECT * FROM purchaseorder_header_xml
/
CREATE OR REPLACE VIEW shipping_instructions_xml AS
SELECT id, name, address, telephone
FROM tab_xmldata
, XMLTABLE('/PurchaseOrder/ShippingInstructions' passing xml_data
COLUMNS
name VARCHAR2(64) path 'name'
,address VARCHAR2(64) path 'address'
,telephone VARCHAR2(10) path 'telephone')
OracIe XML DB and Forms Integration
Page 8
/
CREATE OR REPLACE VIEW shipping_instructions
AS SELECT * FROM shipping_instructions_xml
/
CREATE OR REPLACE VIEW line_items_xml AS
SELECT id, partid, item_number, description, unit_price, quantity
FROM tab_xmldata
, XMLTABLE('/PurchaseOrder/LineItems/LineItem' passing xml_data
COLUMNS
partid VARCHAR2(15) path 'Part/@Id'
,item_number VARCHAR2(30) path '@ItemNumber'
,description VARCHAR2(45) path 'Description'
,unit_price VARCHAR2(15) path 'Part/@UnitPrice'
,quantity NUMBER(5,2) path 'Part/@Quantity')
/
CREATE OR REPLACE VIEW line_items
AS SELECT * FROM line_items_xml
/
In the aboe DDL, there are XXX_XML iews, which contains the XPA1l expressions, and there are other relational iews
created on top o these XXX_XML iews. 1he reason is that Oracle lorms at the moment does not allow data blocks to be
based on iews containing XPath. As a workaround, additional relational iews are created.
1he next step is to deelop the GUI to display the data. 1his GUI will be deeloped using Oracle lorms as the main purpose o
this paper is to show Oracle lorms deelopers how to integrate Oracle XML DB based on the iews created in step 6.
loweer, we will not discuss the steps to create the orms in this paper.
OracIe XML DB and Forms Integration
Page 9
Step 7 - Form to dispIay data
lere is the sample orm that can be downloaded with other code.
Import or Lxport XML iles. 1ype the ilename
And click the start button
INS1ALLING AND RUNNING 1HL DLMO
Please note that his paper does not deal with Oracle XML DB installation o coniguration, it is assumed that you are working
with oracle database 9i rel 2 and aboe and XML DB is installed and conigured on your database. \our database listener is
conigured to run on deault port o 1521 and it also accepts l1P requests.
Conigure or install XML DB in the database
Lxecute the create_resource.sql with SYS account or with user haing S\SDBA priilege.
Register the XML schema in the database using register_schema.sql. 1his can be done under scott user or any
other demo user.
Create the table tab_xmldata using create_objects.ddl
Create XML iews using xml_views.sql.
Create the utility package pak_utility.pak
1he aboe scripts can be run against Oracle database 9.2.0.5 and aboe.
OracIe XML DB and Forms Integration
Page 10
Steps to run the OracIe Forms demo
The Import Process
Choose the Import radio button on the top let o the screen.
1ype in the XML ile name with the ull path, in the purchase order XML file ield.
Click the start import button.
The Export Process
Choose the Lxport radio button on the top let o the screen.
1ype in the XML ile name with the ull path, in the purchase order XML file ield.
Select the purchase order record rom the Purchase Orders block or which the XML ile has to be exported.
Click the start Lxport button.
View XML content
Select the purchase order record rom the Purchase Orders block or which the XML ile has to be iewed.
Click the Show XML button.
DeIete a Purchase Order from the database
Select the purchase order record rom the Purchase Orders block or which the XML ile has to be exported.
Click the Delete Order button.
CONCLUSION
Using XML DB eatures, we were able to represent complex-structured XML data in a relational ormat and integrate with an
Oracle lorms application. 1his integration proides a simple, lexible, and powerul solution to process XML iles without
writing a single line o Jaa code or accessing the ile system on the database serer. Most importantly, the entire processing low
takes place natiely inside the database and the results are eectiely displayed using Oracle lorms. 1his proides huge
perormance gains when large olumes o XML iles hae to be processed.
In short, Oracle XML DB has not only met our business requirements in high perormance XML processing, it has also
proided us with a rich set o database-natie capabilities to simpliy and accelerate the deelopment, deployment, and
maintenance eort o a critical business application.
OracIe XML DB and Forms Integration
ApriI 2006
Author: Raghu Shyam T, TechnicaI Manager, Robert Bosch India Limited
Contributing Authors: Geoff Lee, PrincipaI Product Manager, OracIe Corporation
OracIe Corporation
WorId Headquarters
500 OracIe Parkway
Redwood Shores, CA 94065
U.S.A.
WorIdwide Inquiries:
Phone: +1.650.506.7000
Fax: +1.650.506.7200
www.oracIe.com
Copyright 2006, Robert Bosch India Limited and OracIe Corporation. AII rights
reserved.
This document is provided for information purposes onIy and the contents hereof
are subject to change without notice. This document is not warranted to be error-
free, nor subject to any other warranties or conditions, whether expressed oraIIy or
impIied in Iaw, incIuding impIied warranties and conditions of merchantabiIity or
fitness for a particuIar purpose. We specificaIIy discIaim any IiabiIity with respect
to this document and no contractuaI obIigations are formed either directIy or
indirectIy by this document. This document may not be reproduced or transmitted
in any form or by any means, eIectronic or mechanicaI, for any purpose, without
our prior written permission. OracIe is a registered trademark of OracIe
Corporation and/or its affiIiates. Other names may be trademarks of their
respective owners.
This document is pubIished onIy for information purpose. THE DOCUMENT IS
PROVIDED WITHOUT ANY REPRESENTATION OR WARRANTY AND IN NO EVENT
SHALL BOSCH BE LIABLE TO ANY OTHER PERSON/ENTITY IN CONNECTION WITH THE
USE OF THE INFORMATION MADE AVAILABLE. BOSCH reserves the right to make changes
and/or updates with respect to the information at any time without notice. Further, BOSCH
does not make any representations about the accuracy of the information contained in the
document for any purpose and aII such information has been provided on an "as is" basis
without warranty of any kind. BOSCH hereby discIaims aII warranties and conditions with
regard to the document incIuding aII impIied warranties and conditions of merchantabiIity,
fitness for a particuIar purpose, titIe and non-infringement. The document is made avaiIabIe
for information purpose onIy, further copying, reproduction or redistribution of the document
is expressIy prohibited. In no event shaII BOSCH be IiabIe for Iost profits or any direct,
indirect, speciaI, punitive, incidentaI or consequentiaI damages arising out of or in
connection with the documents.BOSCH is registered trademark of Robert Bosch and its
subsidary.