Insert XML file into Relational database model - no XMLTYPE!

Dear all,
How can I store a known complex XML file into an existing relational database WITHOUT using xmltypes in the database ?
I read the article on DBMS_XMLSTORE. DBMS_XMLSTORE indeed partially bridges the gap between XML and RDBMS to a certain extent, namely for simply structured XML (canonical structure) and simple tables.
However, when the XML structure will become arbitrary and rapidly evolving, surely there must be a way to map XML to a relational model more flexibly.
We work in a java/Oracle10 environment that receives very large XML documents from an independent data management source. These files comply with an XML schema. That is all we know. Still, all these data must be inserted/updated daily in an existing relational model. Quite an assignment isn't it ?
The database does and will not contain XMLTYPES, only plain RDBMS tables.
Are you aware of a framework/product or tool to do what DBMS_XMLSTORE does but with any format of XML file ? If not, I am doomed.
Cheers.
Luc.
Edited by: user6693852 on Jan 13, 2009 7:02 AM

In case you decide to follow my advice, here's a simple example showing how to do this.. (Note the XMLTable syntax is the preferred approach in 10gr2 and later..
SQL> spool testase.log
SQL> --
SQL> connect / as sysdba
Connected.
SQL> --
SQL> set define on
SQL> set timing on
SQL> --
SQL> define USERNAME = XDBTEST
SQL> --
SQL> def PASSWORD = XDBTEST
SQL> --
SQL> def USER_TABLESPACE = USERS
SQL> --
SQL> def TEMP_TABLESPACE = TEMP
SQL> --
SQL> drop user &USERNAME cascade
  2  /
old   1: drop user &USERNAME cascade
new   1: drop user XDBTEST cascade
User dropped.
Elapsed: 00:00:00.59
SQL> grant create any directory, drop any directory, connect, resource, alter session, create view to &USERNAME identified by &PASS
ORD
  2  /
old   1: grant create any directory, drop any directory, connect, resource, alter session, create view to &USERNAME identified by &
ASSWORD
new   1: grant create any directory, drop any directory, connect, resource, alter session, create view to XDBTEST identified by XDB
EST
Grant succeeded.
Elapsed: 00:00:00.01
SQL> alter user &USERNAME default tablespace &USER_TABLESPACE temporary tablespace &TEMP_TABLESPACE
  2  /
old   1: alter user &USERNAME default tablespace &USER_TABLESPACE temporary tablespace &TEMP_TABLESPACE
new   1: alter user XDBTEST default tablespace USERS temporary tablespace TEMP
User altered.
Elapsed: 00:00:00.00
SQL> connect &USERNAME/&PASSWORD
Connected.
SQL> --
SQL> var SCHEMAURL varchar2(256)
SQL> var XMLSCHEMA CLOB
SQL> --
SQL> set define off
SQL> --
SQL> begin
  2    :SCHEMAURL := 'http://xmlns.example.com/askTom/TransactionList.xsd';
  3    :XMLSCHEMA :=
  4  '<?xml version="1.0" encoding="UTF-8"?>
  5  <!--W3C Schema generated by XMLSpy v2008 rel. 2 sp2 (http://www.altova.com)-->
  6  <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xdb="http://xmlns.oracle.com/xdb" xdb:storeVarrayAsTable="true">
  7     <xs:element name="TransactionList" type="transactionListType" xdb:defaultTable="LOCAL_TABLE"/>
  8     <xs:complexType name="transactionListType"  xdb:maintainDOM="false" xdb:SQLType="TRANSACTION_LIST_T">
  9             <xs:sequence>
10                     <xs:element name="Transaction" type="transactionType" maxOccurs="unbounded" xdb:SQLCollType="TRANSACTION_V"
>
11             </xs:sequence>
12     </xs:complexType>
13     <xs:complexType name="transactionType" xdb:maintainDOM="false"  xdb:SQLType="TRANSACTION_T">
14             <xs:sequence>
15                     <xs:element name="TradeVersion" type="xs:integer"/>
16                     <xs:element name="TransactionId" type="xs:integer"/>
17                     <xs:element name="Leg" type="legType" maxOccurs="unbounded" xdb:SQLCollType="LEG_V"/>
18             </xs:sequence>
19             <xs:attribute name="id" type="xs:integer" use="required"/>
20     </xs:complexType>
21     <xs:complexType name="paymentType"  xdb:maintainDOM="false" xdb:SQLType="PAYMENT_T">
22             <xs:sequence>
23                     <xs:element name="StartDate" type="xs:date"/>
24                     <xs:element name="Value" type="xs:integer"/>
25             </xs:sequence>
26             <xs:attribute name="id" type="xs:integer" use="required"/>
27     </xs:complexType>
28     <xs:complexType name="legType"  xdb:maintainDOM="false"  xdb:SQLType="LEG_T">
29             <xs:sequence>
30                     <xs:element name="LegNumber" type="xs:integer"/>
31                     <xs:element name="Basis" type="xs:integer"/>
32                     <xs:element name="FixedRate" type="xs:integer"/>
33                     <xs:element name="Payment" type="paymentType" maxOccurs="unbounded"  xdb:SQLCollType="PAYMENT_V"/>
34             </xs:sequence>
35             <xs:attribute name="id" type="xs:integer" use="required"/>
36     </xs:complexType>
37  </xs:schema>';
38  end;
39  /
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.00
SQL> set define on
SQL> --
SQL> declare
  2    res boolean;
  3    xmlSchema xmlType := xmlType(:XMLSCHEMA);
  4  begin
  5    dbms_xmlschema.registerSchema
  6    (
  7      schemaurl => :schemaURL,
  8      schemadoc => xmlSchema,
  9      local     => TRUE,
10      genTypes  => TRUE,
11      genBean   => FALSE,
12      genTables => TRUE,
13      ENABLEHIERARCHY => DBMS_XMLSCHEMA.ENABLE_HIERARCHY_NONE
14    );
15  end;
16  /
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.26
SQL> desc LOCAL_TABLE
Name                                                                   Null?    Type
TABLE of SYS.XMLTYPE(XMLSchema "http://xmlns.example.com/askTom/TransactionList.xsd" Element "TransactionList") STORAGE Object-rela
ional TYPE "TRANSACTION_LIST_T"
SQL> --
SQL> create or replace VIEW TRAN_VIEW
  2  as
  3  select
  4    extractvalue(x.column_value,'/Transaction/TradeVersion/text()') tradeversion,
  5    extractvalue(x.column_value,'/Transaction//text()') transactionid
  6  from
  7    local_table,
  8    table(xmlsequence(extract(OBJECT_VALUE,'/TransactionList/Transaction'))) x
  9  /
View created.
Elapsed: 00:00:00.01
SQL> create or replace VIEW TRAN_LEG_VIEW
  2  as
  3  select
  4    extractvalue(x.column_value,'/Transaction/TransactionId/text()') transactionid,
  5    extractvalue(y.column_value,'/Leg/Basis/text()') leg_basis,
  6    extractValue(y.column_value,'/Leg/FixedRate/text()') leg_fixedrate
  7  from
  8    local_table,
  9    table(xmlsequence(extract(OBJECT_VALUE,'/TransactionList/Transaction'))) x,
10    table(xmlsequence(extract(x.column_value,'/Transaction/Leg'))) y
11  /
View created.
Elapsed: 00:00:00.01
SQL> create or replace VIEW TRAN_LEG_PAY_VIEW
  2  as
  3  select
  4    extractvalue(x.column_value,'/Transaction/TransactionId/text()') transactionid,
  5    extractvalue(y.column_value,'/Leg/LegNumber/text()') leg_legnumber,
  6    extractvalue(z.column_value,'/Payment/StartDate/text()') pay_startdate,
  7    extractValue(z.column_value,'/Payment/Value/text()') pay_value
  8  from
  9    local_table,
10    table(xmlsequence(extract(OBJECT_VALUE,'/TransactionList/Transaction'))) x,
11    table(xmlsequence(extract(x.column_value,'/Transaction/Leg'))) y,
12    table(xmlsequence(extract(y.column_value,'/Leg/Payment'))) z
13  /
View created.
Elapsed: 00:00:00.03
SQL> desc TRAN_VIEW
Name                                                                   Null?    Type
TRADEVERSION                                                                    NUMBER(38)
TRANSACTIONID                                                                   VARCHAR2(4000)
SQL> --
SQL> desc TRAN_LEG_VIEW
Name                                                                   Null?    Type
TRANSACTIONID                                                                   NUMBER(38)
LEG_BASIS                                                                       NUMBER(38)
LEG_FIXEDRATE                                                                   NUMBER(38)
SQL> --
SQL> desc TRAN_LEG_PAY_VIEW
Name                                                                   Null?    Type
TRANSACTIONID                                                                   NUMBER(38)
LEG_LEGNUMBER                                                                   NUMBER(38)
PAY_STARTDATE                                                                   DATE
PAY_VALUE                                                                       NUMBER(38)
SQL> --
SQL> create or replace VIEW TRAN_VIEW_XMLTABLE
  2  as
  3  select t.*
  4    from LOCAL_TABLE,
  5         XMLTable
  6         (
  7            '/TransactionList/Transaction'
  8            passing OBJECT_VALUE
  9            columns
10            TRADE_VERSION  NUMBER(4) path 'TradeVersion/text()',
11            TRANSACTION_ID NUMBER(4) path 'TransactionId/text()'
12         ) t
13  /
View created.
Elapsed: 00:00:00.01
SQL> create or replace VIEW TRAN_LEG_VIEW_XMLTABLE
  2  as
  3  select t.TRANSACTION_ID, L.*
  4    from LOCAL_TABLE,
  5         XMLTable
  6         (
  7            '/TransactionList/Transaction'
  8            passing OBJECT_VALUE
  9            columns
10            TRANSACTION_ID NUMBER(4) path 'TransactionId/text()',
11            LEG            XMLType   path 'Leg'
12         ) t,
13         XMLTABLE
14         (
15           '/Leg'
16           passing LEG
17           columns
18           LEG_NUMBER     NUMBER(4) path 'LegNumber/text()',
19           LEG_BASIS      NUMBER(4) path 'Basis/text()',
20           LEG_FIXED_RATE NUMBER(4) path 'FixedRate/text()'
21         ) l
22  /
View created.
Elapsed: 00:00:00.01
SQL> create or replace VIEW TRAN_LEG_PAY_VIEW_XMLTABLE
  2  as
  3  select TRANSACTION_ID, L.LEG_NUMBER, P.*
  4    from LOCAL_TABLE,
  5         XMLTable
  6         (
  7            '/TransactionList/Transaction'
  8            passing OBJECT_VALUE
  9            columns
10            TRANSACTION_ID NUMBER(4) path 'TransactionId/text()',
11            LEG            XMLType   path 'Leg'
12         ) t,
13         XMLTABLE
14         (
15           '/Leg'
16           passing LEG
17           columns
18           LEG_NUMBER     NUMBER(4) path 'LegNumber/text()',
19           PAYMENT        XMLType   path 'Payment'
20         ) L,
21         XMLTABLE
22         (
23           '/Payment'
24           passing PAYMENT
25           columns
26           PAY_START_DATE     DATE      path 'StartDate/text()',
27           PAY_VALUE          NUMBER(4) path 'Value/text()'
28         ) p
29  /
View created.
Elapsed: 00:00:00.03
SQL> desc TRAN_VIEW_XMLTABLE
Name                                                                   Null?    Type
TRADE_VERSION                                                                   NUMBER(4)
TRANSACTION_ID                                                                  NUMBER(4)
SQL> --
SQL> desc TRAN_LEG_VIEW_XMLTABLE
Name                                                                   Null?    Type
TRANSACTION_ID                                                                  NUMBER(4)
LEG_NUMBER                                                                      NUMBER(4)
LEG_BASIS                                                                       NUMBER(4)
LEG_FIXED_RATE                                                                  NUMBER(4)
SQL> --
SQL> desc TRAN_LEG_PAY_VIEW_XMLTABLE
Name                                                                   Null?    Type
TRANSACTION_ID                                                                  NUMBER(4)
LEG_NUMBER                                                                      NUMBER(4)
PAY_START_DATE                                                                  DATE
PAY_VALUE                                                                       NUMBER(4)
SQL> --
SQL> set long 10000 pages 100 lines 128
SQL> set timing on
SQL> set autotrace on explain
SQL> set heading on feedback on
SQL> --
SQL> VAR DOC1 CLOB
SQL> VAR DOC2 CLOB
SQL> --
SQL> begin
  2    :DOC1 :=
  3  '<TransactionList>
  4    <Transaction id="1">
  5      <TradeVersion>1</TradeVersion>
  6      <TransactionId>1</TransactionId>
  7      <Leg id="1">
  8        <LegNumber>1</LegNumber>
  9        <Basis>1</Basis>
10        <FixedRate>1</FixedRate>
11        <Payment id="1">
12          <StartDate>2000-01-01</StartDate>
13          <Value>1</Value>
14        </Payment>
15        <Payment id="2">
16          <StartDate>2000-01-02</StartDate>
17          <Value>2</Value>
18        </Payment>
19      </Leg>
20      <Leg id="2">
21        <LegNumber>2</LegNumber>
22        <Basis>2</Basis>
23        <FixedRate>2</FixedRate>
24        <Payment id="1">
25          <StartDate>2000-02-01</StartDate>
26          <Value>10</Value>
27        </Payment>
28        <Payment id="2">
29          <StartDate>2000-02-02</StartDate>
30          <Value>20</Value>
31        </Payment>
32      </Leg>
33    </Transaction>
34    <Transaction id="2">
35      <TradeVersion>2</TradeVersion>
36      <TransactionId>2</TransactionId>
37      <Leg id="1">
38        <LegNumber>21</LegNumber>
39        <Basis>21</Basis>
40        <FixedRate>21</FixedRate>
41        <Payment id="1">
42          <StartDate>2002-01-01</StartDate>
43          <Value>21</Value>
44        </Payment>
45        <Payment id="2">
46          <StartDate>2002-01-02</StartDate>
47          <Value>22</Value>
48        </Payment>
49      </Leg>
50      <Leg id="22">
51        <LegNumber>22</LegNumber>
52        <Basis>22</Basis>
53        <FixedRate>22</FixedRate>
54        <Payment id="21">
55          <StartDate>2002-02-01</StartDate>
56          <Value>210</Value>
57        </Payment>
58        <Payment id="22">
59          <StartDate>2002-02-02</StartDate>
60          <Value>220</Value>
61        </Payment>
62      </Leg>
63    </Transaction>
64  </TransactionList>';
65    :DOC2 :=
66  '<TransactionList>
67    <Transaction id="31">
68      <TradeVersion>31</TradeVersion>
69      <TransactionId>31</TransactionId>
70      <Leg id="31">
71        <LegNumber>31</LegNumber>
72        <Basis>31</Basis>
73        <FixedRate>31</FixedRate>
74        <Payment id="31">
75          <StartDate>3000-01-01</StartDate>
76          <Value>31</Value>
77        </Payment>
78      </Leg>
79    </Transaction>
80  </TransactionList>';
81  end;
82  /
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.01
SQL> insert into LOCAL_TABLE values ( xmltype(:DOC1))
  2  /
1 row created.
Elapsed: 00:00:00.01
Execution Plan
Plan hash value: 1
| Id  | Operation                | Name        | Rows  | Bytes | Cost (%CPU)| Time     |
|   0 | INSERT STATEMENT         |             |     1 |   100 |     1   (0)| 00:00:01 |
|   1 |  LOAD TABLE CONVENTIONAL | LOCAL_TABLE |       |       |            |          |
SQL> insert into LOCAL_TABLE values ( xmltype(:DOC2))
  2  /
1 row created.
Elapsed: 00:00:00.01
Execution Plan
Plan hash value: 1
| Id  | Operation                | Name        | Rows  | Bytes | Cost (%CPU)| Time     |
|   0 | INSERT STATEMENT         |             |     1 |   100 |     1   (0)| 00:00:01 |
|   1 |  LOAD TABLE CONVENTIONAL | LOCAL_TABLE |       |       |            |          |
SQL> select * from TRAN_VIEW_XMLTABLE
  2  /
TRADE_VERSION TRANSACTION_ID
            1              1
            2              2
           31             31
3 rows selected.
Elapsed: 00:00:00.03
Execution Plan
Plan hash value: 650975545
| Id  | Operation          | Name                           | Rows  | Bytes | Cost (%CPU)| Time     |
|   0 | SELECT STATEMENT   |                                |     3 |   168 |     3   (0)| 00:00:01 |
|   1 |  NESTED LOOPS      |                                |     3 |   168 |     3   (0)| 00:00:01 |
|*  2 |   TABLE ACCESS FULL| SYS_NTGgl+TKyhQnWoFRSrCxeX9g== |     3 |   138 |     3   (0)| 00:00:01 |
|*  3 |   INDEX UNIQUE SCAN| SYS_C0010174                   |     1 |    10 |     0   (0)| 00:00:01 |
Predicate Information (identified by operation id):
   2 - filter("SYS_NC_TYPEID$" IS NOT NULL)
   3 - access("NESTED_TABLE_ID"="LOCAL_TABLE"."SYS_NC0000800009$")
Note
   - dynamic sampling used for this statement
SQL> select * from TRAN_LEG_VIEW_XMLTABLE
  2  /
TRANSACTION_ID LEG_NUMBER  LEG_BASIS LEG_FIXED_RATE
             1          1          1              1
             1          2          2              2
             2         21         21             21
             2         22         22             22
            31         31         31             31
5 rows selected.
Elapsed: 00:00:00.04
Execution Plan
Plan hash value: 1273661583
| Id  | Operation           | Name                           | Rows  | Bytes | Cost (%CPU)| Time     |
|   0 | SELECT STATEMENT    |                                |     5 |   560 |     7  (15)| 00:00:01 |
|*  1 |  HASH JOIN          |                                |     5 |   560 |     7  (15)| 00:00:01 |
|   2 |   NESTED LOOPS      |                                |     3 |   159 |     3   (0)| 00:00:01 |
|*  3 |    TABLE ACCESS FULL| SYS_NTGgl+TKyhQnWoFRSrCxeX9g== |     3 |   129 |     3   (0)| 00:00:01 |
|*  4 |    INDEX UNIQUE SCAN| SYS_C0010174                   |     1 |    10 |     0   (0)| 00:00:01 |
|*  5 |   TABLE ACCESS FULL | SYS_NTUmyermF/S721C/2UXo40Uw== |     5 |   295 |     3   (0)| 00:00:01 |
Predicate Information (identified by operation id):
   1 - access("SYS_ALIAS_1"."NESTED_TABLE_ID"="SYS_ALIAS_0"."SYS_NC0000800009$")
   3 - filter("SYS_NC_TYPEID$" IS NOT NULL)
   4 - access("NESTED_TABLE_ID"="LOCAL_TABLE"."SYS_NC0000800009$")
   5 - filter("SYS_NC_TYPEID$" IS NOT NULL)
Note
   - dynamic sampling used for this statement
SQL> select * from TRAN_LEG_PAY_VIEW_XMLTABLE
  2  /
TRANSACTION_ID LEG_NUMBER PAY_START  PAY_VALUE
             1          1 01-JAN-00          1
             1          1 02-JAN-00          2
             1          2 01-FEB-00         10
             1          2 02-FEB-00         20
             2         21 01-JAN-02         21
             2         21 02-JAN-02         22
             2         22 01-FEB-02        210
             2         22 02-FEB-02        220
            31         31 01-JAN-00         31
9 rows selected.
Elapsed: 00:00:00.07
Execution Plan
Plan hash value: 4004907785
| Id  | Operation            | Name                           | Rows  | Bytes | Cost (%CPU)| Time     |
|   0 | SELECT STATEMENT     |                                |     9 |  1242 |    10  (10)| 00:00:01 |
|*  1 |  HASH JOIN           |                                |     9 |  1242 |    10  (10)| 00:00:01 |
|*  2 |   HASH JOIN          |                                |     5 |   480 |     7  (15)| 00:00:01 |
|   3 |    NESTED LOOPS      |                                |     3 |   159 |     3   (0)| 00:00:01 |
|*  4 |     TABLE ACCESS FULL| SYS_NTGgl+TKyhQnWoFRSrCxeX9g== |     3 |   129 |     3   (0)| 00:00:01 |
|*  5 |     INDEX UNIQUE SCAN| SYS_C0010174                   |     1 |    10 |     0   (0)| 00:00:01 |
|*  6 |    TABLE ACCESS FULL | SYS_NTUmyermF/S721C/2UXo40Uw== |     5 |   215 |     3   (0)| 00:00:01 |
|*  7 |   TABLE ACCESS FULL  | SYS_NTelW4ZRtKS+WKqCaXhsHnNQ== |     9 |   378 |     3   (0)| 00:00:01 |
Predicate Information (identified by operation id):
   1 - access("NESTED_TABLE_ID"="SYS_ALIAS_1"."SYS_NC0000900010$")
   2 - access("SYS_ALIAS_1"."NESTED_TABLE_ID"="SYS_ALIAS_0"."SYS_NC0000800009$")
   4 - filter("SYS_NC_TYPEID$" IS NOT NULL)
   5 - access("NESTED_TABLE_ID"="LOCAL_TABLE"."SYS_NC0000800009$")
   6 - filter("SYS_NC_TYPEID$" IS NOT NULL)
   7 - filter("SYS_NC_TYPEID$" IS NOT NULL)
Note
   - dynamic sampling used for this statement
SQL>Out of interest why are you so against using XMLType...
Edited by: mdrake on Jan 13, 2009 8:25 AM

Similar Messages

  • Insert XML file into Relational database model without using XMLTYPE tables

    Dear all,
    How can I store a known complex XML file into an existing relational database WITHOUT using xmltypes in the database ?
    I read the article on DBMS_XMLSTORE. DBMS_XMLSTORE indeed partially bridges the gap between XML and RDBMS to a certain extent, namely for simply structured XML (canonical structure) and simple tables.
    However, when the XML structure will become arbitrary and rapidly evolving, surely there must be a way to map XML to a relational model more flexibly.
    We work in a java/Oracle10 environment that receives very large XML documents from an independent data management source. These files comply with an XML schema. That is all we know. Still, all these data must be inserted/updated daily in an existing relational model. Quite an assignment isn't it ?
    The database does and will not contain XMLTYPES, only plain RDBMS tables.
    Are you aware of a framework/product or tool to do what DBMS_XMLSTORE does but with any format of XML file ? If not, I am doomed.
    Constraints : Input via XML files defined by third party
    Storage : relational database model with hundreds of tables and thousands of existing queries that can not be touched. The model must not be altered.
    Target : get this XML into the database on a daily basis via an automated process.
    Cheers.
    Luc.

    Luc,
    your Doomed !
    If you would try something like DBMS_XMLSTORE, you probably would be into serious performance problems in your case, very fast, and it would be very difficult to manage.
    If you would use a little bit of XMLType stuff, you would be able to shred the data into the relational model very fast and controlable. Take it from me, I am one of those old geezers like Mr. Tom Kyte way beyond 40 years (still joking). No seriously. I started out as a classical PL/SQL, Forms Guy that switched after two years to become a "DBA 1.0" and Mr Codd and Mr Date were for years my biggest hero's. I have the utmost respect for Mr. Tom Kyte for all his efforts for bringing the concepts manual into the development world. Just to name some off the names that influenced me. But you will have to work with UNSTRUCTURED data (as Mr Date would call it). 80% of the data out there exists off it. Stuff like XMLTABLE and XML VIEWs bridge the gap between that unstructured world and the relational world. It is very doable to drag and drop an XML file into the XMLDB database into a XMLtype table and or for instance via FTP. From that point on it is in the database. From there you could move into relational tables via XMLTABLE methods or XML Views.
    You could see the described method as a filtering option so XML can be transformed into relational data. If you don't want any XML in your current database, then create an small Oracle database with XML DB installed (if doable 11.1.0.7 regarding the best performance --> all the new fast optimizer stuff etc). Use that database as a staging area that does all the XML shredding for you into relational components and ship the end result via database links and or materialized views or other probably known methodes into your relational database that isn't allowed to have XMLType.
    This way you would keep your realtional Oracle database clean and have the Oracle XML DB staging database do all the filtering and shredding into relational components.
    Throwing the XML DB option out off the window beforehand would be like replacing your Mercedes with a bicycle. With both you will be able to travel the distance from Paris to Rome, but it will take you a hell of lot longer.
    :-)

  • Performance problems loading an XML file into oracle database

    Hello ODI Guru's,
    I am trying to load and XML file into the database after doing simple business validations. But the interface takes hours to complete.
    1. The XML files are large in size >200 Mb. We have an XSD file for the schema definition instead of a DTD.
    2. We used the external database feature for loading these files in database.
    The following configuration was used in the XML Data Server:
    jdbc:snps:xml?f=D:\CustomerMasterData1\CustomerMasterInitialLoad1.xml&d=D:\CustomerMasterData1\CustomerMasterInitialLoad1.xsd&re=initialLoad&s=CM&db_props=oracle&ro=true
    3. Now we reverse engineer the XML files and created models using ODI Designer
    4. Similar thing was done for the target i.e. an Oracle database table as well.
    5. Next we created a simple interface with one-to-one mapping from the XSD schema to the Oracle database table and executed the interface. This execution takes more than one hour to complete.
    6. We are running ODI client on Windows XP Professional SP2.
    7. The Oracle database server(Oracle 10g 10.2.0.3) for the target schema as well as the ODI master and work repositories are on the same machine.
    8. I tried changing the following properties but it is not making much visible difference:
    use_prepared_statements=Y
    use_batch_update=Y
    batch_update_size=510
    commit_periodically=Y
    num_inserts_before_commit=30000
    I have another problem that when I set batch_update_size to value greater that 510 I get the following error:
    java.sql.SQLException: class org.xml.sax.SAXException
    class java.lang.ArrayIndexOutOfBoundsException said -32413
    at com.sunopsis.jdbc.driver.xml.v.a(v.java)
    The main concern is why should the interface taking so long to execute.
    Please send suggestions to resolve the problem.
    Thanks in advance,
    Best Regards,
    Nikunj

    Approximately how many rows are you trying to insert?
    One of the techniques which I found improved performance for this scenario was to extract from the xml to a flat file, then to use SQL*LOADER or external tables to load the data into Oracle.

  • A query while  importing  an XML file into a Database Table

    Hi,
    I am Creating an ODI Project to import an XML file into a Database Table.With the help of the following link
    http://www.oracle.com/webfolder/technetwork/tutorials/obe/fmw/odi/odi_11g/odi_project_xml-to-table/odi_project_xml-to-table.htm
    I am facing a problem while creating Physical Schema for the XML Source Model.
    For the
    Schema(Schema)
    and
    Schema(Work Schema) field they have selected GEO_D.
    What is GEO_D here??
    or
    What I have to select here?
    1) schema of the xml file (NB:-I havn't created any .xsd or .dtd file for my .xml file)
    or
    2)my target servers schema
    Please tell me what I'll do??
    Thanks

    and
    Schema(Work Schema) field they have selected GEO_D.
    What is GEO_D here??This is the schema name which is specified in the XML file .
    What I have to select here?
    1) schema of the xml file (NB:-I havn't created any .xsd or .dtd file for my .xml file)Yes
    2)my target servers schema
    Please tell me what I'll do??
    Thanks

  • Load XML file into oracle database

    Hi
    i have a xml file and the XSD(Schema definition file for XML). i need to load the xml file into the database.
    Can you please tell me the best approach for this ?

    There are plenty of examples of this on the XML DB Forum.
    Here is a link to the FAQ for that forum...
    XML DB FAQ

  • Insert Insert XML file into multiple records in Oracle Database

    I would like to find out if it is possible to insert a single XML file into multiple records or tuples in a Oracle database table. I have a single XML file which is at multiple levels. The meta data for the levels are common and each level can have meta data of their own in addition. I do not have any meta data field which will uniquely determine whether the data belongs to Root level, Intermediate level or at the document level. Is there any way I can determine which level the meta data belongs to and thereby make a corresponding entry into the database table tuple? For example I could have an attribute called level which is going to be present only in the database table and not in the XML file. If level=1 then it corresponds to "Root" meta data, if level=2 then it corresponds to "Intermediate" level and if level=3 then it corresponds to meta data at document level. I need a way to calculate the value for level from the XML file and thereby insert the meta data element into a tuple in a single table in Oracle.

    Hi,
    extract your xml and then you can use insert all clause.
    here's very small example on 10.2.0.1.0
    SQL> create table table1(id number,val varchar2(10));
    Table created.
    SQL> create table table2(id number,val varchar2(10));
    Table created.
    SQL> insert all
      2  into table1 values(id,val)
      3  into table2 values(id2,val2)
      4  select extractValue(x.col,'/a/id1') id
      5        ,extractValue(x.col,'/a/value') val
      6        ,extractValue(x.col,'/a/value2') val2
      7        ,extractValue(x.col,'/a/id2') id2
      8  from (select xmltype('<a><id1>1</id1><value>a</value><id2>2</id2><value2>b</value2></a>') col from dual) x;
    2 rows created.
    SQL> select * from table1;
            ID VAL                                                                 
             1 a                                                                   
    SQL> select * from table2;
            ID VAL                                                                 
             2 b                                                                    Ants

  • Loading an XML file into a database table.

    What is the convenient way to parse XML data present in a data file in server?

    Hi;
    Please check:
    http://riteshkk2000.blogspot.com/2012/01/loadimport-xml-file-into-database-table .html
    http://docs.oracle.com/cd/E18283_01/appdev.112/e16659/xdb03usg.htm#BABIFADB
    http://www.oracle.com/technetwork/articles/quinlan-xml-095823.html
    Regard
    Helios

  • Inserting XML file  into a Table

    Hello,
    Can someone provide me with a sample code to load xml files into a table. Thanks a lot.
    Rajeesh

    Keeping my fingers crossed that this quote from "Building XML Oracle Applications" by Steve Muench (O'Reilly & Associates, 2000, ISBN 1-56592-691-9) falls into the "fair use" category, and that you want it in PL/SQL, here is a procedure:
    PROCEDURE insertXMLFile
    (dir VARCHAR2, file VARCHAR2, name VARCHAR2 := NULL) IS
    theBFile BFILE;
    theCLob CLOB;
    theDocName VARCHAR2(200) := NVL(name,file);
    BEGIN
    -- (1) Insert a new row into xml_documents with an empty CLOB, and
    -- (2) Retrieve the empty CLOB into a variable with RETURNING.INTO
    INSERT INTO stylesheets(docname,sheet) VALUES(theDocName,empty_clob( ))
    RETURNING sheet INTO theCLob;
    -- (3) Get a BFile handle to the external file
    theBFile := BFileName(dir,file);
    -- (4) Open the file
    dbms_lob.fileOpen(theBFile);
    -- (5) Copy the contents of the BFile into the empty CLOB
    dbms_lob.loadFromFile(dest_lob => theCLob, src_lob => theBFile, amount => dbms_lob.getLength(theBFile));
    -- (6) Close the file and commit
    dbms_lob.fileClose(theBFile);
    COMMIT;
    END;

  • While inserting values from a xml file into the database.

    Dear Forum Members,
    While using Samp10.java (given in XSU!2_ver1_2_1/oracleXSU12/Sample)for inserting values from xml file Sampdoc.xml into database table xmltest_tab1,the error shown below appears on the DOS prompt.
    The code for sam10 is:
    import oracle.xml.sql.dml.*;
    import java.sql.*;
    import oracle.jdbc.driver.*;
    import oracle.jdbc.*;
    import java.net.*;
    public class samp10
    public static void main(String args[]) throws SQLException
    String tabName = "xmltest_tab1";
    String fileName = "sampdoc.xml";
    try{
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection conn=DriverManager.getConnection("jdbc:odbc:BookingSealinerScott","scott","tiger");
    OracleXMLSave sav = new OracleXMLSave(conn, tabName);
    URL url = sav.createURL(fileName);
    int rowCount = sav.insertXML(url);
    System.out.println(" successfully inserted "+rowCount+
    " rows into "+ tabName);
    conn.close();
    }catch (Exception e){e.printStackTrace();}
    The Structure of Sampdoc.xml is:
    <?xml version="1.0"?>
    <ROWSET>
    <ROW num="1">
    <EMPNO>7369</EMPNO>
    <ENAME>SMITH</ENAME>
    <JOB>CLERK</JOB>
    </ROW>
    <ROW num="2">
    <EMPNO>7499</EMPNO>
    <ENAME>ALLEN</ENAME>
    <JOB>SALESMAN</JOB>
    </ROW>
    <ROW num="3">
    <EMPNO>7521</EMPNO>
    <ENAME>WARD</ENAME>
    <JOB>SALESMAN</JOB>
    </ROW>
    </ROWSET>
    Description of table xmltest_tab1 is:
    SQL> desc xmltest_tab1;
    Name Null? Type
    EMPNO NUMBER(4)
    ENAME CHAR(10)
    JOB VARCHAR2(9)
    Error Displayed is:
    A nonfatal internal JIT (3.00.078(x)) error 'Structured Exception(c0000005)' has
    occurred in :
    'oracle/xml/sql/dml/OracleXMLSave.cleanLobList ()V': Interpreting method.
    Please report this error in detail to http://java.sun.com/cgi-bin/bugreport.cgi
    oracle.xml.sql.OracleXMLSQLException: sun.jdbc.odbc.JdbcOdbcConnection
    at oracle.xml.sql.dml.OracleXMLSave.saveXML(OracleXMLSave.java:1967)
    at oracle.xml.sql.dml.OracleXMLSave.saveXML(OracleXMLSave.java:1880)
    at oracle.xml.sql.dml.OracleXMLSave.insertXML(OracleXMLSave.java:1013)
    at samp10.main(samp10.java:36)
    Press any key to continue . . .
    Please send me the solution as soon as possible.
    Thanks,
    Waiting for your Reply,
    Bye,
    Vineet Choudhary
    Email id: [email protected]
    null

    Go and read about JDBC. You need to know some basics before asking such a st&*id questions.
    Paul

  • How to load XML files into ORACLE8i database?

    SAP data is being extracted into XML format (via IDOC) files which are being transferred to an ORACLE8i box. There will be a large amount of data transferred on a daily basis which will include updates and inserts. From all the information that I have read on this subject there are 2 options available :
    1. XML-SQL Utility - which converts XML into INSERT, UPDATE or DELETE SQL. There does not appear to be that much functionality available by this method for decodes, transformations on the input data.
    2. SQL*Loader - There was a statement in 1 piece of documentation stating that SQL*Loader could be used for loading XML format data files. I cannot however find any further information on how this is achieved or how it works.
    If anyone has any experience in loading XML format data files using either of the above methods (preferably SQL*Loader as it has more functionality) then could you please provide me with examples or guidance on this matter? Any help would be greatly appreciated as I am not familiar with XML format data files. I am from an Oracle 7.3 background but do not have much experience with Oracle 8 onwards.
    Disclaimer.
    Any views expressed in the above paragraphs are my own and not that of Hewlett Packard Ltd.

    We are loading XML into our database using CLOB datatypes. We don't use the XSU for inserts as it is too slow. We parse the incoming XML document into a PL/SQL record type and then build a generic insert. This might not work well if you have many tags to parse into columns. We also store the entire XML CLOB into a column without parsing the individual tags into separate columns. We then use Intermedia Text for fast, index-based searching within the XML column.
    Check out The Oracle XML Portal website for code examples on how to do this:
    www.webspedite.com/oracle

  • How to get ALL validate-errors while insert xml-file into xml_schema_table

    How to get all validate-errors while using insert into xml_schema when having a xml-instance with more then one error inside ?
    Hi,
    I can validate a xml-file by using isSchemaValid() - function to get the validate-status 0 or 1 .
    To get a error-output about the reason I do validate
    the xml-file against xdb-schema, by insert it into schema_table.
    When more than one validate-errors inside the xml-file,
    the exception shows me the first error only.
    How to get all errors at one time ?
    regards
    Norbert
    ... for example like this matter:
    declare
         xmldoc CLOB;
         vStatus varchar
    begin     
    -- ... create xmldoc by using DBMS_XMLGEN ...
    -- validate by using insert ( I do not need insert ;-) )      
         begin
         -- there is the xml_schema in xdb with defaultTable XML_SCHEMA_DEFAULT_TABLE     
         insert into XML_SCHEMA_DEFAULT_TABLE values (xmltype(xmldoc) ) ;
         vStatus := 'XML-Instance is valid ' ;
         exception
         when others then
         -- it's only the first error while parsing the xml-file :     
              vStatus := 'Instance is NOT valid: '||sqlerrm ;
              dbms_output.put_line( vStatus );      
         end ;
    end ;

    If I am not mistaken, the you probably could google this one while using "Steven Feuerstein Validation" or such. I know I have seen a very decent validation / error handling from Steven about this.

  • How to load a XML file into the database

    Hi,
    I've always only loaded data into the database by using SQL-Loader and the data format was Excel or ASCII
    Now I have to load a XML.
    How can I do?
    The company where I work has Oracle vers. 8i (don't laugh, please)
    Thanks in advance!

    Hi,
    Tough job especially if the XML data is complex. The have been some similar question in the forum:
    Using SQL Loader to load an XML File -- use 1 field's data for many records
    SQL Loader to upload XML file
    Hope they help.
    Regards,
    Sujoy

  • LPX-00004 - Problems while inserting xml files in a xmltype column

    I've faced two problems while trying to insert xml files into my table containing a xmltype column:
    create table xml_test (id number(20),content xmltype)
    I use following java code for writing xml docs into db:
         conn.setAutoCommit(false);
         OraclePreparedStatement stmt = (OraclePreparedStatement)
              conn.prepareStatement("INSERT INTO xml_test (id,content) VALUES(?,?)");
         File file = new File(file1);
         InputStream in1 = new FileInputStream(file1);
         Reader r1 = new BufferedReader(new InputStreamReader(in1, "UTF-8"));
         int len = 0;
         StringBuffer text = new StringBuffer();
         while ((len = r1.read()) != -1) {
              text.append((char) len);
         in1.close();
         r1.close();
         XMLType poXML1 = XMLType.createXML(conn, text.toString());
         for (int i = 1; i <= 1; i++) {
              stmt.setInt(1, i);
              stmt.setObject(2, poXML1);
              stmt.execute();
         conn.commit();
    1. problem: occures only if a xml schema has been assoicated to the specific xmltype column. it seems that the length of a specific xml tag in the document is limited. but why?
    java.sql.SQLException: ORA-22814: attribute or element value is larger than specified in type
         at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
         at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:289)
         at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:573)
         at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1891)
         at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteFetch(TTC7Protocol.java:1093)
         at oracle.jdbc.driver.OracleStatement.executeNonQuery(OracleStatement.java:2047)
         at oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.java:1940)
         at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2709)
         at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:589)
         at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:656)
         at test.insertXML(test.java:84)
         at test.main(test.java:261)
    hier the xml-schema of the xmltype column "content":
    <?xml version="1.0" encoding="UTF-8"?>
    <!--W3C Schema generated by XML Spy v4.4 U (http://www.xmlspy.com)-->
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
         <xs:element name="AUTOR-ID" type="xs:string"/>
         <xs:element name="BODY" type="xs:string"/>
         <xs:element name="CONTENT">
              <xs:complexType>
                   <xs:sequence>
                        <xs:element ref="METADATEN"/>
                        <xs:element ref="BODY"/>
                   </xs:sequence>
                   <xs:attribute name="content-id" type="xs:string" use="required"/>
              </xs:complexType>
         </xs:element>
         <xs:element name="DATUM" type="xs:string"/>
         <xs:element name="KEYWORD" type="xs:string"/>
         <xs:element name="METADATEN">
              <xs:complexType>
                   <xs:sequence>
                        <xs:element ref="DATUM"/>
                        <xs:element ref="TITEL" maxOccurs="unbounded"/>
                        <xs:element ref="KEYWORD" maxOccurs="unbounded"/>
                        <xs:element ref="AUTOR-ID"/>
                   </xs:sequence>
              </xs:complexType>
         </xs:element>
         <xs:element name="TITEL" type="xs:string"/>
    </xs:schema>
    2. problem: hier i have no idea what is happening ... please help
    java.sql.SQLException: ORA-31011: XML parsing failed
    ORA-19202: Error occurred in XML processing
    LPX-00004: internal error "MultiChar overflow"
    Error at line 61
         at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
         at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:289)
         at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:573)
         at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1891)
         at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteFetch(TTC7Protocol.java:1093)
         at oracle.jdbc.driver.OracleStatement.executeNonQuery(OracleStatement.java:2047)
         at oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.java:1940)
         at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2709)
         at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:589)
         at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:656)
         at test.insertXML(test.java:53)
         at test.main(test.java:259)

    It's hard for me to tell you more without seeing your instance data, but for problem #1, if you look at the underlying SQL types being generated by your schema, you will see that the default SQL mapping for a "string" in your schema is a VARCHAR2(4000) (and I believe this would be only 2000 for a varying width character set like UTF8).
    You can specify that you wish this column to be mapped as a CLOB in your schema if this is the problem. Also note that there is a 64K limit on the size of an individual node in XMLType.

  • Inserting XML content into Database

    Hallo
    i´m new to Oracle.
    i want to insert xml content into the database. for testing i installed the version 10g on a windowsxp computer.
    i read the oracle xmldb developer´s guide. on page 3-4 ff. it is explained how i can insert content into the database. that´s how i did it (with isqlplus):
    create table example1(key_column varchar2(10) primary key, xml_column xmltype)
    -->works fine
    create table example2 of xmltype
    -->works fine
    now i made a directory under c:\myXmlFilesForDb in WinXp
    create directory xmldir as 'c:/myXmlFilesForDb in WinXp'
    (also tried: create directory xmldir as 'c:\myXmlFilesForDb in WinXp')
    --> in this directory is a file named: mydokument.xml
    --> works fine
    insert into example2 values(xmltype(bfilename('xmldir','mydokument.xml'), nls_charset_id('AL32UTF8')))
    the following error message is displayed (in German):
    ORA-22285: Verzeichnis oder Datei für FILEOPEN-Vorgang nicht vorhanden
    ORA-06512: in "SYS.DBMS_LOB",Zeile 523
    ORA-06512: in "SYS:XMLTYPE",Zeile 287
    ORA-06512: in Zeile 1
    whats wrong? can anybody help me please?
    ohhh....
    thank you very much
    cu
    George

    Directory entries are case sensitive.
    Select * From dba_directories to ensure you case is the same as you are using in your insert statement.
    Are you using the same user? if not grant read on directory directoryname to username;
    try to just select.
    select dbms_lob.getLength(BFileName('directoryname','filename.xml'))
    as length
    from dual;

  • Insert large XML files into 11g

    Can anyone post an example of inserting XML files into a XMLType table? I can use the following to insert files into a CLOB table without problems.
    $lob = oci_new_descriptor($conn, OCI_D_LOB);
              $sql = "insert into D (DATASET_ID, XML_DATA)
    values(
                   dataset_id_seq.NEXTVAL,
                   EMPTY_CLOB( )
              ) RETURNING XML_DATA into :the_blob";
              $stmt = oci_parse($conn, $sql);
              oci_bind_by_name($stmt, ':the_blob', $lob, -1, OCI_B_CLOB);
              oci_execute($stmt, OCI_DEFAULT);
              if ($lob->savefile($f)){
                   oci_commit($conn);
                   echo "Blob successfully uploaded\n";
              }else{
                   echo "Couldn't upload Blob\n";
              oci_free_descriptor($lob);
              oci_free_statement($stmt);

    A small example to insert xml file into oracle xml DB
    //$Xml contains the xml file you want to insert into the database.
    $insertXML = <<<EOF
    DECLARE xml CLOB := $Xml; begin INSERT INTO purchaseorder_as_column VALUES (1,XMLType(xml)); end;
    EOF;
    $stid = oci_parse($c, $insertXML);
    oci_execute($stid);
    //retrieve the xml data from the that table
    $sql = "select XMLTYPE.GetClobVal(xml_document) from purchaseorder_as_column where id=1";
    $stid = oci_parse($c, $sql);
    oci_execute($stid);
    $res = oci_fetch_row($stid);
    $xmldoc = $res[0]->load();
    //Then use simple xml extensions or others as you like to deal with the XML document
    $sxe = simplexml_load_string($xmldoc);
    //other operations with tthe xml data
    var_dump($sxe);

Maybe you are looking for