Partial XMLType toObject

Hi,
I have an XML schema registered with Oracle. The schema is annotated and during registration the PL/SQL types are created. I can validate an XMLType with this schema, as well as use toObject to populate an object with data from the XMLType. The XML looks like this:
<root>
<complexObject>...... very complex object with many elements, sub-elements and sequences .......</complexObject>
<complexObject>...... very complex object with many elements, sub-elements and sequences .......</complexObject>
<complexObject>...... very complex object with many elements, sub-elements and sequences .......</complexObject>
<complexObject>...... very complex object with many elements, sub-elements and sequences .......</complexObject>
<complexObject>...... very complex object with many elements, sub-elements and sequences .......</complexObject>
</root>
There can be a lot of "complexObject" elements in the sequence and the XML can be huge.
The <root> element has the corresponding T_ROOT type, the <complexObject> elements had the corresponding T_COMPLEXOBJECT type. T_ROOT has a VARRAY of T_COMPLEXOBJECT.
So, like I said before, I can populate an object of type T_ROOT from the XML without an issue using toObject on the XMLType. However, due to the complexity and size of the XML, I want to split the big XML into multiple T_COMPLEXOBJECT objects. I can do this using XPath extract in a query, returning me one XMLType row per "complexObject". Here is where I'm stuck: I want to use a cursor on the above query and process each "complexObject" one by one. For this, I need to somehow be able to do something similar with toObject, but on the "complexObject" XMLType fragment only to populate an object of type T_COMPLEXOBJECT, not on the whole T_ROOT.
If I do:
l_xml.toObject(l_obj, 'myschema.xsd', 'complexObject');
instead of
l_xml.toObject(l_obj_root, 'myschema.xsd', 'root');
I get:
ORA-31043: Element 'complexObject' not globally defined in schema 'myschema.xsd'
ORA-06512: at "SYS.XMLTYPE", line 196
ORA-06512: at line 38
Thanks!
Edited by: 1005635 on May 13, 2013 10:40 AM

Here's an example
SQL> --
SQL> -- def XMLDIR = &1
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:01.31
SQL> grant unlimited tablespace, create any directory, drop any directory, connect, resource, alter session, create view to &USERNAME identified by &PASSWORD
  2  /
old   1: grant unlimited tablespace, create any directory, drop any directory, connect, resource, alter session, create view to &USERNAME identified by &PASSWOR
D
new   1: grant unlimited tablespace, create any directory, drop any directory, connect, resource, alter session, create view to XDBTEST identified by XDBTEST
Grant succeeded.
Elapsed: 00:00:00.03
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> -- create or replace directory XMLDIR as '&XMLDIR'
SQL> -- /
SQL> var SCHEMAURL       varchar2(256)
SQL> var XMLSCHEMA       CLOB
SQL> var INSTANCE        CLOB;
SQL> --
SQL> set define off
SQL> --
SQL> alter session set events='31098 trace name context forever'
  2  /
Session altered.
Elapsed: 00:00:00.00
SQL>
SQL> begin
  2    :XMLSCHEMA :=
  3  '<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" version="1.0">
  4          <xs:element name="PurchaseOrder" type="PurchaseOrderType"/>
  5          <xs:complexType name="PurchaseOrderType">
  6                  <xs:sequence>
  7                          <xs:element name="Reference" type="ReferenceType"/>
  8                          <xs:element name="Actions" type="ActionsType"/>
  9                          <xs:element name="Rejection" type="RejectionType" minOccurs="0"/>
10                          <xs:element name="Requestor" type="RequestorType"/>
11                          <xs:element name="User" type="UserType"/>
12                          <xs:element name="CostCenter" type="CostCenterType"/>
13                          <xs:element name="ShippingInstructions" type="ShippingInstructionsType"/>
14                          <xs:element name="SpecialInstructions" type="SpecialInstructionsType"/>
15                          <xs:element name="LineItems" type="LineItemsType"/>
16                  </xs:sequence>
17                  <xs:attribute name="DateCreated" type="xs:dateTime" use="required"/>
18          </xs:complexType>
19          <xs:complexType name="LineItemsType">
20                  <xs:sequence>
21                          <xs:element name="LineItem" type="LineItemType" maxOccurs="unbounded"/>
22                  </xs:sequence>
23          </xs:complexType>
24          <xs:complexType name="LineItemType">
25                  <xs:sequence>
26                          <xs:element name="Part" type="PartType"/>
27                          <xs:element name="Quantity" type="QuantityType"/>
28                  </xs:sequence>
29                  <xs:attribute name="ItemNumber" type="xs:integer"/>
30          </xs:complexType>
31          <xs:complexType name="PartType">
32                  <xs:simpleContent>
33                          <xs:extension base="UPCCodeType">
34                                  <xs:attribute name="Description" type="DescriptionType" use="required"/>
35                                  <xs:attribute name="UnitPrice" type="MoneyType" use="required"/>
36                          </xs:extension>
37                  </xs:simpleContent>
38          </xs:complexType>
39          <xs:simpleType name="ReferenceType">
40                  <xs:restriction base="xs:string">
41                          <xs:minLength value="18"/>
42                          <xs:maxLength value="30"/>
43                  </xs:restriction>
44          </xs:simpleType>
45          <xs:complexType name="ActionsType">
46                  <xs:sequence>
47                          <xs:element name="Action" maxOccurs="4">
48                                  <xs:complexType>
49                                          <xs:sequence>
50                                                  <xs:element name="User" type="UserType"/>
51                                                  <xs:element name="Date" type="DateType" minOccurs="0"/>
52                                          </xs:sequence>
53                                  </xs:complexType>
54                          </xs:element>
55                  </xs:sequence>
56          </xs:complexType>
57          <xs:complexType name="RejectionType">
58                  <xs:all>
59                          <xs:element name="User" type="UserType" minOccurs="0"/>
60                          <xs:element name="Date" type="DateType" minOccurs="0"/>
61                          <xs:element name="Comments" type="CommentsType" minOccurs="0"/>
62                  </xs:all>
63          </xs:complexType>
64          <xs:complexType name="ShippingInstructionsType">
65                  <xs:sequence>
66                          <xs:element name="name" type="NameType" minOccurs="0"/>
67                          <xs:element name="address" type="AddressType" minOccurs="0"/>
68                          <xs:element name="telephone" type="TelephoneType" minOccurs="0"/>
69                  </xs:sequence>
70          </xs:complexType>
71          <xs:simpleType name="MoneyType">
72                  <xs:restriction base="xs:decimal">
73                          <xs:fractionDigits value="2"/>
74                          <xs:totalDigits value="12"/>
75                  </xs:restriction>
76          </xs:simpleType>
77          <xs:simpleType name="QuantityType">
78                  <xs:restriction base="xs:decimal">
79                          <xs:fractionDigits value="4"/>
80                          <xs:totalDigits value="8"/>
81                  </xs:restriction>
82          </xs:simpleType>
83          <xs:simpleType name="UserType">
84                  <xs:restriction base="xs:string">
85                          <xs:minLength value="1"/>
86                          <xs:maxLength value="10"/>
87                  </xs:restriction>
88          </xs:simpleType>
89          <xs:simpleType name="RequestorType">
90                  <xs:restriction base="xs:string">
91                          <xs:minLength value="0"/>
92                          <xs:maxLength value="128"/>
93                  </xs:restriction>
94          </xs:simpleType>
95          <xs:simpleType name="CostCenterType">
96                  <xs:restriction base="xs:string">
97                          <xs:minLength value="1"/>
98                          <xs:maxLength value="4"/>
99                          <xs:enumeration value=""/>
100                          <xs:enumeration value="A0"/>
101                          <xs:enumeration value="A10"/>
102                          <xs:enumeration value="A20"/>
103                          <xs:enumeration value="A30"/>
104                          <xs:enumeration value="A40"/>
105                          <xs:enumeration value="A50"/>
106                          <xs:enumeration value="A60"/>
107                          <xs:enumeration value="A70"/>
108                          <xs:enumeration value="A80"/>
109                          <xs:enumeration value="A90"/>
110                          <xs:enumeration value="A100"/>
111                          <xs:enumeration value="A110"/>
112                  </xs:restriction>
113          </xs:simpleType>
114          <xs:simpleType name="PurchaseOrderNumberType">
115                  <xs:restriction base="xs:integer"/>
116          </xs:simpleType>
117          <xs:simpleType name="SpecialInstructionsType">
118                  <xs:restriction base="xs:string">
119                          <xs:minLength value="0"/>
120                          <xs:maxLength value="1000"/>
121                  </xs:restriction>
122          </xs:simpleType>
123          <xs:simpleType name="NameType">
124                  <xs:restriction base="xs:string">
125                          <xs:minLength value="1"/>
126                          <xs:maxLength value="20"/>
127                  </xs:restriction>
128          </xs:simpleType>
129          <xs:simpleType name="AddressType">
130                  <xs:restriction base="xs:string">
131                          <xs:minLength value="1"/>
132                          <xs:maxLength value="256"/>
133                  </xs:restriction>
134          </xs:simpleType>
135          <xs:simpleType name="TelephoneType">
136                  <xs:restriction base="xs:string">
137                          <xs:minLength value="1"/>
138                          <xs:maxLength value="24"/>
139                  </xs:restriction>
140          </xs:simpleType>
141          <xs:simpleType name="DateType">
142                  <xs:restriction base="xs:date"/>
143          </xs:simpleType>
144          <xs:simpleType name="CommentsType">
145                  <xs:restriction base="xs:string">
146                          <xs:minLength value="1"/>
147                          <xs:maxLength value="1000"/>
148                  </xs:restriction>
149          </xs:simpleType>
150          <xs:simpleType name="DescriptionType">
151                  <xs:restriction base="xs:string">
152                          <xs:minLength value="1"/>
153                          <xs:maxLength value="128"/>
154                  </xs:restriction>
155          </xs:simpleType>
156          <xs:simpleType name="UPCCodeType">
157                  <xs:restriction base="xs:string">
158                          <xs:minLength value="11"/>
159                          <xs:maxLength value="14"/>
160                          <xs:pattern value="\d{11}"/>
161                          <xs:pattern value="\d{12}"/>
162                          <xs:pattern value="\d{13}"/>
163                          <xs:pattern value="\d{14}"/>
164                  </xs:restriction>
165          </xs:simpleType>
166  </xs:schema>';
167    :INSTANCE :=
168  '<PurchaseOrder>
169     <Reference>ABULL-20100809203001136PDT</Reference>
170     <Actions>
171        <Action>
172           <User>ACABRIO</User>
173        </Action>
174     </Actions>
175     <Rejection/>
176     <Requestor>Alexis Bull</Requestor>
177     <User>ABULL</User>
178     <CostCenter>A50</CostCenter>
179     <ShippingInstructions>
180        <name>Alexis Bull</name>
181        <address>2011 Interiors Blvd,
182  South San Francisco,
183  California 99236
184  United States of America</address>
185        <telephone>950-720-3387</telephone>
186     </ShippingInstructions>
187     <SpecialInstructions>COD</SpecialInstructions>
188     <LineItems>
189        <LineItem ItemNumber="1" >
190           <Part Description="Scary Movie" UnitPrice="19.95">717951004857</Part>
191           <Quantity>5.0</Quantity>
192        </LineItem>
193        <LineItem ItemNumber="2" >
194           <Part Description="The Faculty" UnitPrice="19.95">717951002280</Part>
195           <Quantity>2.0</Quantity>
196        </LineItem>
197        <LineItem ItemNumber="3">
198           <Part Description="Phantom of the Paradise" UnitPrice="27.95">24543023777</Part>
199           <Quantity>3.0</Quantity>
200        </LineItem>
201     </LineItems>
202  </PurchaseOrder>';
203  end;
204  /
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.00
SQL> declare
  2    V_XML_SCHEMA xmlType := XMLType(:XMLSCHEMA1);end;
  3  /
SP2-0552: Bind variable "XMLSCHEMA1" not declared.
Elapsed: 00:00:00.00
SQL> --
SQL> declare
  2    V_XMLSCHEMA XMLTYPE := XMLTYPE(:XMLSCHEMA);
  3  begin
  4    DBMS_XMLSCHEMA.registerSchema(
  5      schemaURL => 'http://localhost:80/home/SCOTT/poSource/xsd/purchaseOrder.xsd',
  6      schemaDoc => V_XMLSCHEMA,
  7      local     => TRUE,
  8      genTypes  => TRUE,
  9      genTables => FALSE
10    );
11  end;
12  /
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.35
SQL> create table PURCHASEORDER
  2         of XMLTYPE
  3         XMLSCHEMA "http://localhost:80/home/SCOTT/poSource/xsd/purchaseOrder.xsd" ELEMENT "PurchaseOrder"
  4  /
Table created.
Elapsed: 00:00:00.10
SQL> call DBMS_XMLSTORAGE_MANAGE.renameCollectionTable (USER,'PURCHASEORDER',NULL,'/PurchaseOrder/LineItems/LineItem','LINEITEM_TABLE',NULL)
  2  /
Call completed.
Elapsed: 00:00:00.87
SQL> call DBMS_XMLSTORAGE_MANAGE.renameCollectionTable (USER,'PURCHASEORDER',NULL,'/PurchaseOrder/Actions/Action','ACTION_TABLE',NULL)
  2  /
Call completed.
Elapsed: 00:00:00.09
SQL> desc PURCHASEORDER
Name                                      Null?    Type
TABLE of SYS.XMLTYPE(XMLSchema "http://localhost:80/home/SCOTT/poSource/xsd/purchaseOrder.xsd" Element "PurchaseOrder") STORAGE Object-relational TYPE "Purchase
OrderType667_T"
SQL> --
SQL> insert into PURCHASEORDER values (XMLTYPE(:INSTANCE))
  2  /
1 row created.
Elapsed: 00:00:00.44
SQL> commit
  2  /
Commit complete.
Elapsed: 00:00:00.00
SQL> create or replace type ACTION_T as object (
  2    USER_NAME                                          VARCHAR2(10 CHAR),
  3    ACTION_DATE                                        DATE
  4  )
  5  /
Type created.
Elapsed: 00:00:00.02
SQL> show errors
No errors.
SQL> /
Type created.
Elapsed: 00:00:00.01
SQL> create or replace type ACTION_V as VARRAY(32767) of ACTION_T
  2  /
Type created.
Elapsed: 00:00:00.01
SQL> show errors
No errors.
SQL> --
SQL> create or replace type ACTIONS_T as object (
  2    ACTION  ACTION_V
  3  )
  4  /
Type created.
Elapsed: 00:00:00.01
SQL> show errors
No errors.
SQL> --
SQL> create or replace type REJECTION_T as object (
  2    USER_NAME                                          VARCHAR2(10 CHAR),
  3    REJECTION_DATE                                     DATE,
  4    COMMENTS                                           VARCHAR2(1000 CHAR)
  5  )
  6  /
Type created.
Elapsed: 00:00:00.01
SQL> show errors
No errors.
SQL> --
SQL> create or replace type SHIPPING_INSTRUCTIONS_T as object (
  2    NAME                                               VARCHAR2(20 CHAR),
  3    ADDRESS                                            VARCHAR2(256 CHAR),
  4    TELEPHONE                                          VARCHAR2(24 CHAR)
  5  )
  6  /
Type created.
Elapsed: 00:00:00.01
SQL> show errors
No errors.
SQL> --
SQL> create or replace type PART_T as object (
  2   PART_TEXT                                          VARCHAR2(14 CHAR),
  3   DESCRIPTION                                        VARCHAR2(128 CHAR),
  4   UNITPRICE                                          NUMBER(14,2)
  5  )
  6  /
Type created.
Elapsed: 00:00:00.01
SQL> show errors
No errors.
SQL> /
Type created.
Elapsed: 00:00:00.00
SQL> create or replace type LINEITEM_T as object (
  2    ITEMNUMBER                                         NUMBER(38),
  3    PART                                               PART_T,
  4    QUANTITY                                           NUMBER(12,4)
  5  )
  6  /
Type created.
Elapsed: 00:00:00.01
SQL> show errors
No errors.
SQL> /
Type created.
Elapsed: 00:00:00.00
SQL> create or replace type LINEITEM_V as VARRAY(32767) of LINEITEM_T
  2  /
Type created.
Elapsed: 00:00:00.01
SQL> show errors
No errors.
SQL> --
SQL> create or replace type LINEITEMS_T as object (
  2    LINEITEM  LINEITEM_V
  3  )
  4  /
Type created.
Elapsed: 00:00:00.01
SQL> show errors
No errors.
SQL> --
SQL> create or replace type PURCHASEORDER_T as object (
  2   DATECREATED                                        TIMESTAMP(6),
  3   REFERENCE                                          VARCHAR2(30 CHAR),
  4   ACTIONS                                            ACTIONS_T,
  5   REJECTION                                          REJECTION_T,
  6   REQUESTOR                                          VARCHAR2(128 CHAR),
  7   USER_NAME                                          VARCHAR2(10 CHAR),
  8   COSTCENTER                                         VARCHAR2(4 CHAR),
  9   SHIPPINGINSTRUCTIONS                               SHIPPING_INSTRUCTIONS_T,
10   SPECIALINSTRUCTIONS                                VARCHAR2(1000 CHAR),
11   LINEITEMS                                          LINEITEMS_T
12  )
13  /
Type created.
Elapsed: 00:00:00.12
SQL> show errors
No errors.
SQL> --
SQL> select PURCHASEORDER_T (
  2           DATECREATED,
  3                                   REFERENCE,
  4                                   ACTIONS_T(
  5                                     CAST(
  6               MULTISET(
  7                 SELECT ACTION_T(
  8                          USER_NAME,
  9                          ACTION_DATE
10                        )
11                   FROM XMLTABLE(
12                         '/Actions/Action'
13                          passing ACTIONS
14                          columns
15                            USER_NAME        VARCHAR2(10 CHAR) path 'User',
16                            ACTION_DATE      DATE              path 'Date'
17                        )
18               ) AS ACTION_V
19             )
20           ),
21           (
22                             select REJECTION_T (
23                      USER_NAME,
24                      REJECTION_DATE,
25                      COMMENTS
26                    )
27               from XMLTABLE(
28                      '/Rejection'
29                      passing REJECTION
30                      columns
31                        USER_NAME         VARCHAR2(10 CHAR)     path 'User',
32                        REJECTION_DATE    DATE                  path 'Date',
33                        COMMENTS          VARCHAR2(1000 CHAR)   path 'Comments'
34                    )
35           ),
36                                   REQUESTOR,
37                                   USER_NAME,
38           COSTCENTER,
39                           (
40                             select SHIPPING_INSTRUCTIONS_T (
41                      USER_NAME,
42                      ADDRESS,
43                      TELEPHONE
44                    )
45               from XMLTABLE(
46                      '/ShippingInstructions'
47                      passing SHIPPING_INSTRUCTIONS
48                      columns
49                        USER_NAME       VARCHAR2(20 CHAR)    path 'name',
50                        ADDRESS         VARCHAR2(256 CHAR)   path 'address',
51                        TELEPHONE       VARCHAR2(24 CHAR)    path 'telephone'
52                    )
53           ),
54           SPECIAL_INSTRUCTIONS,
55                                   LINEITEMS_T(
56                                     CAST(
57               MULTISET(
58                 SELECT LINEITEM_T (
59                          ITEMNUMBER,
60                          (
61                            select PART_T(
62                                     PART_TEXT,
63                                     DESCRIPTION,
64                                     UNITPRICE
65                                   )
66                              from XMLTABLE(
67                                     '/Part'
68                                     passing PART
69                                     columns
70                                       PART_TEXT          VARCHAR2(14 CHAR)  path 'text()',
71                                       DESCRIPTION        VARCHAR2(128 CHAR) path '@Description',
72                                       UNITPRICE          NUMBER(14,2)       path '@UnitPrice'
73                                   )
74                          ),
75                          QUANTITY
76                        )
77                   FROM XMLTABLE(
78                         '/LineItems/LineItem'
79                          passing LINEITEMS
80                          columns
81                            ITEMNUMBER   NUMBER(38)   path '@ItemNumber',
82                            PART         XMLTYPE      path 'Part',
83                            QUANTITY     NUMBER(12,4) path 'Quantity'
84                        )
85               ) AS LINEITEM_V
86             )
87           )
88         )
89    from PURCHASEORDER,
90         XMLTABLE(
91           '/PurchaseOrder'
92           passing OBJECT_VALUE
93           columns
94              DATECREATED               TIMESTAMP(6)        path '@DateCreated',
95                                                  REFERENCE                 VARCHAR2(30 CHAR)   path 'Reference',
96                                                  ACTIONS                   XMLTYPE             path 'Actions',
97                                                  REJECTION                 XMLTYPE             path 'Rejection',
98                                                  REQUESTOR                 VARCHAR2(128 CHAR)  path 'Requestor',
99                                                  USER_NAME                 VARCHAR2(10 CHAR)   path 'User',
100                                                  COSTCENTER                VARCHAR2(4 CHAR)    path 'CostCenter',
101                                                  SHIPPING_INSTRUCTIONS     XMLTYPE             path 'ShippingInstructions',
102                                                  SPECIAL_INSTRUCTIONS      VARCHAR2(1000 CHAR) path 'SpecialInstructions',
103                                                  LINEITEMS                 XMLType             path 'LineItems'
104                     )
105  /
PURCHASEORDER_T(DATECREATED,REFERENCE,ACTIONS_T(CAST(MULTISET(SELECTACTION_T(USE
PURCHASEORDER_T(NULL, 'ABULL-20100809203001136PDT', ACTIONS_T(ACTION_V(ACTION_T(
'ACABRIO', NULL))), REJECTION_T(NULL, NULL, NULL), 'Alexis Bull', 'ABULL', 'A50'
, SHIPPING_INSTRUCTIONS_T('Alexis Bull', '2011 Interiors Blvd,
South San Francisco,
California 99236
United States of America', '950-720-3387'), 'COD', LINEITEMS_T(LINEITEM_V(LINEIT
EM_T(1, PART_T('717951004857', 'Scary Movie', 19.95), 5), LINEITEM_T(2, PART_T('
717951002280', 'The Faculty', 19.95), 2), LINEITEM_T(3, PART_T('24543023777', 'P
hantom of the Paradise', 27.95), 3))))
Elapsed: 00:00:00.11
SQL> quitEdited by: mdrake on May 13, 2013 11:33 PM

Similar Messages

  • Xmltype.toObject() creates partly empty object

    xmltype.toObject() creates an object of the type created when registering the XML schema but in this object all text-elements are empty.
    I registered an XML Schema in XDB 9i release 2.
    When I create an instance of xmltype using CreateSchemabasedXML, toObjects creates an object in which all varchar "members" are empty. members which consist of furter object-types are not null, but within these objects the varchar members again are empty.
    Is toObject() only partially implemented?

    Seems you encountered the bug described in
    Bug 3578226 - ORA-22814 when using XMLtype.toObject with empty XML elements.
    The workaround mentioned there states to »store empty elements like <TEST/>«. Try if that helps.

  • XMLType.ToObject()

    Hi there,
    I am running into a problem when (in Oracle9i Enterprise Edition Release 9.2.0.6.0) trying to map an XML document contained in an XMLType variable to a corresponding object-type variable using the XMLType.ToObject() function.
    The problem occurs when the XML contains "repeating" fragments.
    I do not know how to define the corresponding object-type in such a way that XMLType.ToObject() does not run into error "ORA-19031: XML element or attribute ... does not match any in type ...".
    For example the following XML:
    ====================
    <MyObject>
    <ELEMENT01>VALUE01</ELEMENT01>
    <ELEMENT02>VALUE02</ELEMENT02>
    <MYGROUP>
    <GROUPELEMENT01>VALUEG01E01</GROUPELEMENT01>
    <GROUPELEMENT02>VALUEG01E02</GROUPELEMENT02>
    </MYGROUP>
    <MYGROUP>
    <GROUPELEMENT01>VALUEG02E01</GROUPELEMENT01>
    <GROUPELEMENT02>VALUEG02E02</GROUPELEMENT02>
    </MYGROUP>
    </MyObject>
    ====================
    The corresponding object-type that I defined is as follows:
    ====================
    create or replace type TP_MYGROUP_REC as object
    (GROUPELEMENT01 varchar2(50)
    ,GROUPELEMENT02 varchar2(50)
    create or replace type TP_MYGROUP_TAB as table of TP_MYGROUP_REC;
    create or replace type TP_MYOBJECT as object
    (ELEMENT01 varchar2(50)
    ,ELEMENT02 varchar2(50)
    ,MYGROUP TP_MYGROUP_TAB
    ====================
    I tested with the following script:
    ====================
    declare
    l_xmltype xmltype;
    l_myobject TP_MYOBJECT;
    begin
    l_xmltype := XMLTYPE
    ('<MyObject>
    <ELEMENT01>VALUE01</ELEMENT01>
    <ELEMENT02>VALUE02</ELEMENT02>
    <MYGROUP>
    <GROUPELEMENT01>VALUEG01E01</GROUPELEMENT01>
    <GROUPELEMENT02>VALUEG01E02</GROUPELEMENT02>
    </MYGROUP>
    <MYGROUP>
    <GROUPELEMENT01>VALUEG02E01</GROUPELEMENT01>
    <GROUPELEMENT02>VALUEG02E02</GROUPELEMENT02>
    </MYGROUP>
    </MyObject>');
    l_xmltype.ToObject(l_myobject);
    end;
    ====================
    This results in: ORA-19031: XML element or attribute GROUPELEMENT01 does not match any in type TP_MYGROUP_REC.
    Does anyone out there know how to define the object-type(s) in such a way that I can cast this type of XML to an object using XMLType.ToObject() ?
    Thanks a lot for your reaction,
    Jaap Kool

    In absence of an XML schema, Oracle uses a canonical mapping between SQL objects and XML.
    For instance, the XML structure corresponding to the object hierarchy defined in the first post is :
    <TP_MYOBJECT>
      <ELEMENT01>VALUE01</ELEMENT01>
      <ELEMENT02>VALUE02</ELEMENT02>
      <MYGROUP>
        <TP_MYGROUP_REC>
          <GROUPELEMENT01>VALUEG01E01</GROUPELEMENT01>
          <GROUPELEMENT02>VALUEG01E02</GROUPELEMENT02>
        </TP_MYGROUP_REC>
        <TP_MYGROUP_REC>
          <GROUPELEMENT01>VALUEG02E01</GROUPELEMENT01>
          <GROUPELEMENT02>VALUEG02E02</GROUPELEMENT02>
        </TP_MYGROUP_REC>
      </MYGROUP>
    </TP_MYOBJECT>Note the additional "TP_MYGROUP_REC" element that encloses the two leaf values.
    With that input, this works :
    SQL> declare
      2    l_xmltype  xmltype;
      3    l_myobject TP_MYOBJECT;
      4  begin
      5    l_xmltype := XMLTYPE(
      6  '<TP_MYOBJECT>
      7    <ELEMENT01>VALUE01</ELEMENT01>
      8    <ELEMENT02>VALUE02</ELEMENT02>
      9    <MYGROUP>
    10      <TP_MYGROUP_REC>
    11        <GROUPELEMENT01>VALUEG01E01</GROUPELEMENT01>
    12        <GROUPELEMENT02>VALUEG01E02</GROUPELEMENT02>
    13      </TP_MYGROUP_REC>
    14      <TP_MYGROUP_REC>
    15        <GROUPELEMENT01>VALUEG02E01</GROUPELEMENT01>
    16        <GROUPELEMENT02>VALUEG02E02</GROUPELEMENT02>
    17      </TP_MYGROUP_REC>
    18    </MYGROUP>
    19  </TP_MYOBJECT>');
    20 
    21    l_xmltype.ToObject(l_myobject);
    22 
    23    dbms_output.put_line(l_myobject.mygroup(1).groupelement01);
    24 
    25  end;
    26  /
    VALUEG01E01
    PL/SQL procedure successfully completed
    Here's the approach you can follow to achieve a "custom" mapping :
    {thread:id=2475819}
    and,
    {message:id=10712117}
    Edited by: odie_63 on 20 déc. 2012 09:54

  • Alternative to XMLTYPE.TOOBJECT to populate a UDT

    Is there any alternative option that can be utilized other than the XMLTYPE.TOOBJECT to populate an oracle object via a clob or raw or XML string?

    Maybe something like this?:
    SQL> DECLARE
       l_xml   XMLTYPE
          := XMLTYPE
               ('<?xml version="1.0"?><root><itm>A</itm><itm>B</itm><itm>C</itm><itm>D</itm></root>'
       TYPE t_num IS TABLE OF VARCHAR2 (50)
          INDEX BY BINARY_INTEGER;
       v_val   t_num;
    BEGIN
       FOR c IN (SELECT ROWNUM, EXTRACTVALUE (COLUMN_VALUE, 'itm/text()') itm
                   FROM TABLE (XMLSEQUENCE (EXTRACT (l_xml, '/root/itm'))))
       LOOP
          v_val (c.ROWNUM) := c.itm;
       END LOOP;
       FOR i IN 1 .. v_val.COUNT
       LOOP
          DBMS_OUTPUT.put_line ('Item ' || i || ': ' || v_val (i));
       END LOOP;
    END;
    Item 1: A
    Item 2: B
    Item 3: C
    Item 4: D
    PL/SQL procedure successfully completed.

  • Seems taht XMLType.toObject() doesn't work well ...

    Hello,
    We are trying to convert XML file into XMLType object and then to our custom object type using registered XSD definition. So we doing this : clob with xml -> XMLObject -> our MMS_T object.
    The problem we experienced with transfering values of "type" and "status" attributes to object values MMS_T.TYPE and MMS_T.STATUS. Note that types MMS_T and ERROR_T are automatically created during schema
    (XSD) registration. See and try Listing 1.
    The second Listing contains anonymous pl/sql block with our testcase, please run it after registering schema. The output You will get should look like this one :
    Schema based
    Well-formed
    <?xml version="1.0" encoding="UTF-8"?>
    <mms-provisioning xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xdb="http://xmlns.oracle.com/xdb"
    type="subscription"
    status="error">
    <error code="1">Some error</error>
    <serviceID>iDnes</ser
    Type:,Status:,Error:1-Some error,ServiceID:iDnes,Method:SMS,MSISDN:+420602609903
    The problem is visible on the last line, where "Type" and "Status" object attributes should have its values that should come from XML, but they haven't. Where we were wrong ?
    Please help,
    Thanks & Regards,
    Radim.
    Note
    ====
    When we are trying to do xml.schemaValidate() in our example, it raises folowong errors :
    ORA-31154: invalid XML document
    ORA-19202: Error occurred in XML processing
    LSX-00310: local element or attribute should be namespace qualified
    ORA-06512: at "SYS.XMLTYPE", line 0
    ORA-06512: at line 27
    Listing 1
    =========
    declare
    xsd clob:=
    '<?xml version="1.0" encoding="UTF-8"?>
    <xs:schema
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:xdb="http://xmlns.oracle.com/xdb"
    elementFormDefault="qualified"
    attributeFormDefault="unqualified"
    xdb:mapStringToNCHAR="false"
    xdb:mapUnboundedStringToLob="false"
    xdb:storeVarrayAsTable="false"
    >
         <xs:element name="mms-provisioning" xdb:SQLType="MMS_T">
              <xs:complexType>
                   <xs:sequence>
                        <xs:element name="error" minOccurs="0" xdb:SQLName="ERROR" xdb:SQLType="ERROR_T">
                             <xs:complexType>
                                  <xs:simpleContent>
                                       <xs:extension base="xs:string">
                                            <xs:attribute name="code" type="xs:decimal" use="required" xdb:SQLName="CODE" xdb:SQLType="NUMBER"/>
                                       </xs:extension>
                                  </xs:simpleContent>
                             </xs:complexType>
                        </xs:element>
                        <xs:element name="serviceID" type="xs:string" xdb:SQLName="SERVICEID" xdb:SQLType="VARCHAR2"/>
                        <xs:element name="method" type="xs:string" xdb:SQLName="METHOD" xdb:SQLType="VARCHAR2"/>
                        <xs:element name="msisdn" type="xs:string" xdb:SQLName="MSISDN" xdb:SQLType="VARCHAR2"/>
                   </xs:sequence>
                   <xs:attribute name="type" type="type_t" use="required" xdb:SQLName="TYP" xdb:SQLType="VARCHAR2"/>
                   <xs:attribute name="status" type="status_t" use="required" xdb:SQLName="STATUS" xdb:SQLType="VARCHAR2"/>
              </xs:complexType>
         </xs:element>
         <xs:simpleType name="status_t">
              <xs:restriction base="xs:string">
                   <xs:maxLength value="30"/>
                   <xs:enumeration value="new"/>
                   <xs:enumeration value="pending"/>
                   <xs:enumeration value="subscribed"/>
                   <xs:enumeration value="error"/>
              </xs:restriction>
         </xs:simpleType>
         <xs:simpleType name="type_t">
              <xs:restriction base="xs:string">
              <xs:maxLength value="30"/>
              <xs:enumeration value="subscription"/>
              <xs:enumeration value="unsubscription"/>
              </xs:restriction>
         </xs:simpleType>
    </xs:schema>';
    begin
    dbms_XMLSchema.RegisterSchema (
    SchemaURL => 'http://www.eurotel.cz/xsd/mms-provisioning.xsd',
    SchemaDoc => xsd
    end;
    Listing 2
    =========
    declare
    o mms_t;
    doc clob :=
    '<?xml version="1.0" encoding="UTF-8"?>
    <mms-provisioning type="subscription" status="error">
         <error code="1">Some error</error>
         <serviceID>iDnes</serviceID>
         <method>SMS</method>
         <msisdn>+420602608696</msisdn>
    </mms-provisioning>';
    xml XMLType;
    begin
    xml := XMLType.createXML(XMLData => doc,schema => 'http://www.eurotel.cz/xsd/mms-provisioning.xsd');
    if xml.isSchemaBased() = 1 then
    dbms_output.put_line('Schema based');
    else
    dbms_output.put_line('Non-Schema based');
    end if;
    if xml.isFragment() = 1 then
    dbms_output.put_line('Fragment');
    else
    dbms_output.put_line('Well-formed');
    end if;
    --Crashes with errors
    --xml.schemaValidate();
    dbms_output.put_line(substr(xml.getstringval(),1,255));
    xml.toObject(o,schema => 'http://www.eurotel.cz/xsd/mms-provisioning.xsd', element => 'mms-provisioning');
    dbms_output.put_line(
    'Type:'||o.typ||
    ',Status:'||o.status||
    ',Error:'||o.error.code||'-'||o.error.sys_xdbbody$||
    ',ServiceID:'||o.serviceid||
    ',Method:'||o.method||
    ',MSISDN:'||o.msisdn);
    end;
    /

    Hello,
    We are trying to convert XML file into XMLType object and then to our custom object type using registered XSD definition. So we doing this : clob with xml -> XMLObject -> our MMS_T object.
    The problem we experienced with transfering values of "type" and "status" attributes to object values MMS_T.TYPE and MMS_T.STATUS. Note that types MMS_T and ERROR_T are automatically created during schema
    (XSD) registration. See and try Listing 1.
    The second Listing contains anonymous pl/sql block with our testcase, please run it after registering schema. The output You will get should look like this one :
    Schema based
    Well-formed
    <?xml version="1.0" encoding="UTF-8"?>
    <mms-provisioning xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xdb="http://xmlns.oracle.com/xdb"
    type="subscription"
    status="error">
    <error code="1">Some error</error>
    <serviceID>iDnes</ser
    Type:,Status:,Error:1-Some error,ServiceID:iDnes,Method:SMS,MSISDN:+420602609903
    The problem is visible on the last line, where "Type" and "Status" object attributes should have its values that should come from XML, but they haven't. Where we were wrong ?
    Please help,
    Thanks & Regards,
    Radim.
    Note
    ====
    When we are trying to do xml.schemaValidate() in our example, it raises folowong errors :
    ORA-31154: invalid XML document
    ORA-19202: Error occurred in XML processing
    LSX-00310: local element or attribute should be namespace qualified
    ORA-06512: at "SYS.XMLTYPE", line 0
    ORA-06512: at line 27
    Listing 1
    =========
    declare
    xsd clob:=
    '<?xml version="1.0" encoding="UTF-8"?>
    <xs:schema
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:xdb="http://xmlns.oracle.com/xdb"
    elementFormDefault="qualified"
    attributeFormDefault="unqualified"
    xdb:mapStringToNCHAR="false"
    xdb:mapUnboundedStringToLob="false"
    xdb:storeVarrayAsTable="false"
    >
         <xs:element name="mms-provisioning" xdb:SQLType="MMS_T">
              <xs:complexType>
                   <xs:sequence>
                        <xs:element name="error" minOccurs="0" xdb:SQLName="ERROR" xdb:SQLType="ERROR_T">
                             <xs:complexType>
                                  <xs:simpleContent>
                                       <xs:extension base="xs:string">
                                            <xs:attribute name="code" type="xs:decimal" use="required" xdb:SQLName="CODE" xdb:SQLType="NUMBER"/>
                                       </xs:extension>
                                  </xs:simpleContent>
                             </xs:complexType>
                        </xs:element>
                        <xs:element name="serviceID" type="xs:string" xdb:SQLName="SERVICEID" xdb:SQLType="VARCHAR2"/>
                        <xs:element name="method" type="xs:string" xdb:SQLName="METHOD" xdb:SQLType="VARCHAR2"/>
                        <xs:element name="msisdn" type="xs:string" xdb:SQLName="MSISDN" xdb:SQLType="VARCHAR2"/>
                   </xs:sequence>
                   <xs:attribute name="type" type="type_t" use="required" xdb:SQLName="TYP" xdb:SQLType="VARCHAR2"/>
                   <xs:attribute name="status" type="status_t" use="required" xdb:SQLName="STATUS" xdb:SQLType="VARCHAR2"/>
              </xs:complexType>
         </xs:element>
         <xs:simpleType name="status_t">
              <xs:restriction base="xs:string">
                   <xs:maxLength value="30"/>
                   <xs:enumeration value="new"/>
                   <xs:enumeration value="pending"/>
                   <xs:enumeration value="subscribed"/>
                   <xs:enumeration value="error"/>
              </xs:restriction>
         </xs:simpleType>
         <xs:simpleType name="type_t">
              <xs:restriction base="xs:string">
              <xs:maxLength value="30"/>
              <xs:enumeration value="subscription"/>
              <xs:enumeration value="unsubscription"/>
              </xs:restriction>
         </xs:simpleType>
    </xs:schema>';
    begin
    dbms_XMLSchema.RegisterSchema (
    SchemaURL => 'http://www.eurotel.cz/xsd/mms-provisioning.xsd',
    SchemaDoc => xsd
    end;
    Listing 2
    =========
    declare
    o mms_t;
    doc clob :=
    '<?xml version="1.0" encoding="UTF-8"?>
    <mms-provisioning type="subscription" status="error">
         <error code="1">Some error</error>
         <serviceID>iDnes</serviceID>
         <method>SMS</method>
         <msisdn>+420602608696</msisdn>
    </mms-provisioning>';
    xml XMLType;
    begin
    xml := XMLType.createXML(XMLData => doc,schema => 'http://www.eurotel.cz/xsd/mms-provisioning.xsd');
    if xml.isSchemaBased() = 1 then
    dbms_output.put_line('Schema based');
    else
    dbms_output.put_line('Non-Schema based');
    end if;
    if xml.isFragment() = 1 then
    dbms_output.put_line('Fragment');
    else
    dbms_output.put_line('Well-formed');
    end if;
    --Crashes with errors
    --xml.schemaValidate();
    dbms_output.put_line(substr(xml.getstringval(),1,255));
    xml.toObject(o,schema => 'http://www.eurotel.cz/xsd/mms-provisioning.xsd', element => 'mms-provisioning');
    dbms_output.put_line(
    'Type:'||o.typ||
    ',Status:'||o.status||
    ',Error:'||o.error.code||'-'||o.error.sys_xdbbody$||
    ',ServiceID:'||o.serviceid||
    ',Method:'||o.method||
    ',MSISDN:'||o.msisdn);
    end;
    /

  • Rumours about xmltype toobject becoming depricated

    We have been using the toobject functionality of the xmltype within
    the 10 database. A few posts on these forums suggest that in the
    future this functionality will become depricated. This worries me.
    I would like to know what the plans are for this functionality.
    Thanks for the reply in advance.

  • Xmltype.toObject() date attribute

    Hi guys,
    I use a 11g database and I am trying to convert an xml into an object
    but I am having problems at oracle date fields
    eg:<CREATED_DATE>2012-08-18T18:15:31.8673829+01:00</CREATED_DATE> cannot be inserted into CREATED_DATE DATE,
    I tried the implicit oracle format yyyy-mm-ddThh24:mi:ss but it does not work, the only things that work is NLS_DATE_FORMAT (dd-mon-yy) .
    Is there any way to do this?
    CREATE OR REPLACE TYPE GROUP_STATEMENT_REC AS OBJECT(
    GROUP_STATEMENT_ID           NUMBER(10), 
    GROUP_ID                     VARCHAR2(5),
    CUSTOMER_ID                  NUMBER(10), 
    CREATED_DATE                 DATE,       
    REPORT_GENERATED_DATE        DATE,       
    EVENT_ID                     NUMBER(10), 
    YEAR                         VARCHAR2(4),
    MONTH                        VARCHAR2(2),
    CURRENCY_CODE                VARCHAR2(3),
    OPENING_BALANCE              NUMBER(17,2),
    CLOSING_BALANCE              NUMBER(17,2),
    CUSTOMER_COLLECTION_HOLD_IND VARCHAR2(1),
    CUSTOMER_DISPUTE_IND         VARCHAR2(1)
    ) FINAL INSTANTIABLE;
    CREATE OR REPLACE TYPE GROUP_STATEMENT_COL IS TABLE OF GROUP_STATEMENT_REC;
    create or replace type gsbox is object (container GROUP_STATEMENT_COL);
    declare
        lc_gs   GROUP_STATEMENT_COL := GROUP_STATEMENT_COL(GROUP_STATEMENT_REC(1,'40666',1000,sysdate,sysdate,11,'2004','10','EUR',123.23,32.23,'Y','N'),
                                                             GROUP_STATEMENT_REC(2,'40600',1001,sysdate-1,sysdate,12,'2004','10','EUR',123.23,32.23,'Y','N'));
        xmlgs         xmltype;
        l_box         gsbox;
        newgs         GROUP_STATEMENT_COL;
      begin
    --dbms_output.put_line(lc_gs.count);
      -- select sys_xmlgen(gsbox(lc_gs)) into xmlgs from dual;
      xmlgs := new XMLType('<?xml version="1.0" encoding="utf-8"?>
    <ROW xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <CONTAINER>
        <GROUP_STATEMENT_REC>
          <GROUP_STATEMENT_ID>0</GROUP_STATEMENT_ID>
          <GROUP_ID>30888</GROUP_ID>
          <CUSTOMER_ID>39</CUSTOMER_ID>
          <CREATED_DATE>2012-08-18T18:15:31.8673829+01:00</CREATED_DATE>
          <REPORT_GENERATED_DATE xsi:nil="true" />
          <EVENT_ID>0</EVENT_ID>
          <YEAR>2012</YEAR>
          <MONTH>7</MONTH>
          <CURRENCY_CODE>GBP</CURRENCY_CODE>
          <OPENING_BALANCE>4405.08</OPENING_BALANCE>
          <CLOSING_BALANCE>4405.08</CLOSING_BALANCE>
          <CUSTOMER_COLLECTION_HOLD_IND>N</CUSTOMER_COLLECTION_HOLD_IND>
          <CUSTOMER_DISPUTE_IND>N</CUSTOMER_DISPUTE_IND>
        </GROUP_STATEMENT_REC>
      </CONTAINER>
    </ROW>');
       --dbms_output.put_line(xmlgs.getStringVal());
       xmlgs.toObject(l_box);
       newgs := l_box.container;
       for i in 1..newgs.count loop
        dbms_output.put_line(newgs(i).GROUP_STATEMENT_ID || ' : ' || newgs(i).GROUP_ID||newgs(i).REPORT_GENERATED_DATE||newgs(i).YEAR||'<<<');
       end loop;
      end;
     

    Hi,
    I am having problems at oracle date fields
    eg:<CREATED_DATE>2012-08-18T18:15:31.8673829+01:00</CREATED_DATE> cannot be inserted into CREATED_DATE DATE,This format maps to the TIMESTAMP WITH TIME ZONE datatype in Oracle.
    Change the CREATED_DATE attribute to :
    CREATED_DATE                 TIMESTAMP WITH TIME ZONE, Then you should be able to do this :
    SQL> alter session set nls_timestamp_tz_format = 'YYYY-MM-DD"T"HH24:MI:SS.FFTZH:TZM';
    Session altered
    SQL> declare
      2 
      3    xmlgs         xmltype;
      4    l_box         gsbox;
      5    newgs         GROUP_STATEMENT_COL;
      6 
      7  begin
      8 
      9    xmlgs := new XMLType('<?xml version="1.0" encoding="utf-8"?>
    10  <ROW xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    11    <CONTAINER>
    12      <GROUP_STATEMENT_REC>
    13        <GROUP_STATEMENT_ID>0</GROUP_STATEMENT_ID>
    14        <GROUP_ID>30888</GROUP_ID>
    15        <CUSTOMER_ID>39</CUSTOMER_ID>
    16        <CREATED_DATE>2012-08-18T18:15:31.8673829+01:00</CREATED_DATE>
    17        <REPORT_GENERATED_DATE xsi:nil="true" />
    18        <EVENT_ID>0</EVENT_ID>
    19        <YEAR>2012</YEAR>
    20        <MONTH>7</MONTH>
    21        <CURRENCY_CODE>GBP</CURRENCY_CODE>
    22        <OPENING_BALANCE>4405.08</OPENING_BALANCE>
    23        <CLOSING_BALANCE>4405.08</CLOSING_BALANCE>
    24        <CUSTOMER_COLLECTION_HOLD_IND>N</CUSTOMER_COLLECTION_HOLD_IND>
    25        <CUSTOMER_DISPUTE_IND>N</CUSTOMER_DISPUTE_IND>
    26 
    27      </GROUP_STATEMENT_REC>
    28    </CONTAINER>
    29  </ROW>');
    30 
    31    xmlgs.toObject(l_box);
    32    newgs := l_box.container;
    33 
    34    for i in 1..newgs.count loop
    35      dbms_output.put_line(newgs(i).CREATED_DATE);
    36    end loop;
    37 
    38  end;
    39  /
    2012-08-18T18:15:31.867383+01:00
    PL/SQL procedure successfully completed

  • XMLType toobject return garbage when open-close tag used .

    Hi,
    one of our developer send me this test case:
    CREATE OR REPLACE
    TYPE SYNC_RESULT AS OBJECT(
        RES_ID    NUMBER(12),
        CHG_ID    NUMBER(12),
        CODE      NUMBER,
        INFO      VARCHAR2(4000),
        INFO_TECH VARCHAR2(4000),
        CONSTRUCTOR FUNCTION SYNC_RESULT RETURN SELF AS RESULT,
        CONSTRUCTOR FUNCTION SYNC_RESULT(c CLOB) RETURN SELF AS RESULT,
        CONSTRUCTOR FUNCTION SYNC_RESULT(x XMLType) RETURN SELF AS RESULT
    CREATE OR REPLACE
    TYPE BODY SYNC_RESULT IS
      CONSTRUCTOR FUNCTION SYNC_RESULT RETURN SELF AS RESULT IS
      BEGIN
          return;
      END;
      CONSTRUCTOR FUNCTION SYNC_RESULT(c CLOB) RETURN SELF AS RESULT IS
      BEGIN
          XMLType(c).toObject(SELF);
          return;
      END;
      CONSTRUCTOR FUNCTION SYNC_RESULT(x XMLType) RETURN SELF AS RESULT IS
      BEGIN
          x.toObject(SELF);
          return;
      END;
    END;
    Wrote file afiedt.buf
      1  declare
      2    s varchar2(2000);
      3    lx_xml XMLType;
      4    lo_sync_result CDI.SYNC_RESULT;
      5  begin
      6    -- Test statements here
      7    s := '<SYNC_RESULT><CODE>1</CODE><INFO>test</INFO><INFO_TECH>test</INFO_TECH></SYNC_RESULT>';
      8    lx_xml := XMLType(s);
      9    lx_xml.toobject(lo_sync_result);
    10    dbms_output.put_line( 'CODE=' || lo_sync_result.CODE);
    11    dbms_output.put_line( 'length(INFO)=' || length(lo_sync_result.INFO) );
    12    dbms_output.put_line( 'INFO=' || substr(lo_sync_result.INFO, 1, 250));
    13* end;
    SQL>
    SQL> /
    CODE=1
    length(INFO)=4
    INFO=test
    PL/SQL procedure successfully completed.
    SQL> ed
    Wrote file afiedt.buf
      1  declare
      2    s varchar2(2000);
      3    lx_xml XMLType;
      4    lo_sync_result SYNC_RESULT;
      5  begin
      6    -- Test statements here
      7    s := '<SYNC_RESULT><CODE>1</CODE><INFO/><INFO_TECH>test</INFO_TECH></SYNC_RESULT>';
      8    lx_xml := XMLType(s);
      9    lx_xml.toobject(lo_sync_result);
    10    dbms_output.put_line( 'CODE=' || lo_sync_result.CODE);
    11    dbms_output.put_line( 'length(INFO)=' || length(lo_sync_result.INFO) );
    12    dbms_output.put_line( 'INFO=' || substr(lo_sync_result.INFO, 1, 250));
    13* end;
    SQL> r
      1  declare
      2    s varchar2(2000);
      3    lx_xml XMLType;
      4    lo_sync_result SYNC_RESULT;
      5  begin
      6    -- Test statements here
      7    s := '<SYNC_RESULT><CODE>1</CODE><INFO/><INFO_TECH>test</INFO_TECH></SYNC_RESULT>';
      8    lx_xml := XMLType(s);
      9    lx_xml.toobject(lo_sync_result);
    10    dbms_output.put_line( 'CODE=' || lo_sync_result.CODE);
    11    dbms_output.put_line( 'length(INFO)=' || length(lo_sync_result.INFO) );
    12    dbms_output.put_line( 'INFO=' || substr(lo_sync_result.INFO, 1, 250));
    13* end;
    CODE=1
    length(INFO)=4000
    INFO=┴☻the run with open-close tag <INFO/> (which is valid from XML point of view) makes garbage out.
    Any ideas ?
    DB 9.2.0.8 EE .
    Regards.
    Greg

    Yes, works on 10.2.0.2
    SQL> declare
      2    s varchar2(2000);
      3    lx_xml XMLType;
      4    lo_sync_result SYNC_RESULT;
      5  begin
      6    -- Test statements here
      7    s := '<SYNC_RESULT><CODE>1</CODE><INFO/><INFO_TECH>test</INFO_TECH></SYNC_RESULT>';
      8    lx_xml := XMLType(s);
      9    lx_xml.toobject(lo_sync_result);
    10    dbms_output.put_line( 'CODE=' || lo_sync_result.CODE);
    11    dbms_output.put_line( 'length(INFO)=' || length(lo_sync_result.INFO) );
    12    dbms_output.put_line( 'INFO=' || substr(lo_sync_result.INFO, 1, 250));
    13  end;
    14  /
    CODE=1
    length(INFO)=
    INFO=
    PL/SQL procedure successfully completed.
    SQL> select * from v$version;
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.2.0 - ProdNot on 9.2.0.4
    SQL> declare
      2    s varchar2(2000);
      3    lx_xml XMLType;
      4    lo_sync_result SYNC_RESULT;
      5  begin
      6    -- Test statements here
      7    s := '<SYNC_RESULT><CODE>1</CODE><INFO/><INFO_TECH>test</INFO_TECH></SYNC_RESULT>';
      8    lx_xml := XMLType(s);
      9    lx_xml.toobject(lo_sync_result);
    10    dbms_output.put_line( 'CODE=' || lo_sync_result.CODE);
    11    dbms_output.put_line( 'length(INFO)=' || length(lo_sync_result.INFO) );
    12    dbms_output.put_line( 'INFO=' || substr(lo_sync_result.INFO, 1, 250));
    13  end;
    14  /
    CODE=1
    length(INFO)=4000
    INFO=Á
    :ý0              
    ³¿    A   :ýX   '¿p   7%Р  7Ó°³
    Procedura PL/SQL completata correttamente.
    SQL>  select * from v$version;
    BANNER
    Oracle9i Enterprise Edition Release 9.2.0.4.0 - 64bit ProductionMax
    [My Italian Oracle blog|http://oracleitalia.wordpress.com/2010/02/07/aggiornare-una-tabella-con-listruzione-merge/]

  • XMLType toobject return invalid number while providing the XML Schema/DTD

    We are exploring an option of converting XML into an oracle object and found toobject procedure that does the job. It works fine without XML Schema and provides XML data as oracle object. But it takes more time in parsing the XML since it uses canonical mapping. I hope by providing XML Schema we can improve the performance of this procedure. However when we use toobject with XML Schema it reports error as INVALID NUMBER irrespective of the input XML changes. Could anyone help me in this regard?

    Sorry
    The option of using toObect() to get an instance of the object that was creaed by regidsteing an XML Schema with the database, or which is associated with an XML Schema that has been registered with the database is depricated and will be removed in the next release. The main reason for this is that we reserve the right to change the structure, naming conventions or any other aspects of the object model we dervie from an XML schema, even as a result of a one-off patch, and consequently any code that was written to rely on this mapping would be broken on a regular basis.
    We do gurantee that code that uses the XML abstraction (eg XPATH/XQUERY) to access the content of the XML will work unchanged...
    In you case you have 2 options...
    1. Use the canonical mapping mechansim
    2. Write code that instantiates the objects from the outpiut of an XMLTable...
    -M

  • Error in creation of Object Type from XML passed

    Hi,
    I am facing a problem creating a appropriate a object type for a XML.
    Below are the details:
    XML Passed
    <mer_offer_action_data>
    <form_id>
    134039588
    </form_id>
    <action_cd>
    OA
    </action_cd>
    <offer_decline_reason_cd>
    </offer_decline_reason_cd>
    <start_dt>
    </start_dt>
    <candidate>
    <ds_prs_id>
    109315
    </ds_prs_id>
    <ds_prs_id>
    110534
    </ds_prs_id>
    <ds_prs_id>
    110059
    </ds_prs_id>
    </candidate>
    </mer_offer_action_data>
    Types Declaration
    +CREATE OR REPLACE type MER_OFF_CANDIDATE
    AS
    OBJECT
    DS_PRS_ID NUMBER
    CREATE OR REPLACE TYPE MER_OFF_CANDIDATE_t
    AS
    TABLE OF MER_OFF_CANDIDATE;
    CREATE OR REPLACE type MER_OFFER_ACT_DATA
    AS
    OBJECT
    FORM_ID NUMBER,
    ACTION_CD VARCHAR2(6),
    OFFER_DECLINE_REASON_CD VARCHAR2(6),
    START_DT VARCHAR2(11),
    CANDIDATE MER_OFF_CANDIDATE_t
    CREATE OR REPLACE TYPE MER_OFFER_ACT_DATA_t
    AS
    TABLE OF MER_OFFER_ACT_DATA;
    CREATE OR REPLACE type MER_OFFER_ACTION_DATA
    AS
    OBJECT
    MER_OFF_ACT_DATA MER_OFFER_ACT_DATA_t
    /+
    My Declaration
    +merOffActDataXML      xmltype;
    merOffActData     MER_OFFER_ACTION_DATA := MER_OFFER_ACTION_DATA(MER_OFFER_ACT_DATA_t());+
    Inside Pl/SQL block
    +-- Converts XML data into user defined type for further processing of data
    xmltype.toobject(merOffActDataXML,merOffActData);+
    when I run the Pl/Sql block it gives me error
    ORA-19031: XML element or attribute FORM_ID does not match any in type ORADBA.MER_OFFER_ACTION_DATA
    which means the object type mapping is wrong
    I would like to know whether the object type I had created is correct or not.
    Thanks for your help
    Beda

    Bedabrata Patel wrote:
    Below are the details:The details except for a description of the problem
    I am facing a problem creating a appropriate a object type for a XML.And which error you are getting
    Error in creation of Object Type http://download.oracle.com/docs/cd/E11882_01/server.112/e10880/toc.htm
    And which version of Oracle you are getting the unknown error creating the unknown problem.

  • Error in creation of Object Type

    Hi,
    I am facing a problem creating a appropriate a object type for a XML.
    Below are the details:
    XML Passed
    <mer_offer_action_data>
         <form_id>
              134039588
         </form_id>
         <action_cd>
              OA
         </action_cd>
         <offer_decline_reason_cd>
         </offer_decline_reason_cd>
         <start_dt>
         </start_dt>
         <candidate>
              <ds_prs_id>
                   109315
              </ds_prs_id>
              <ds_prs_id>
                   110534
              </ds_prs_id>
              <ds_prs_id>
                   110059
              </ds_prs_id>
         </candidate>
    </mer_offer_action_data>
    Types Declaration
    +CREATE OR REPLACE type MER_OFF_CANDIDATE
    AS
    OBJECT
    DS_PRS_ID NUMBER
    CREATE OR REPLACE TYPE MER_OFF_CANDIDATE_t
    AS
    TABLE OF MER_OFF_CANDIDATE;
    CREATE OR REPLACE type MER_OFFER_ACT_DATA
    AS
    OBJECT
    FORM_ID NUMBER,
    ACTION_CD VARCHAR2(6),
    OFFER_DECLINE_REASON_CD VARCHAR2(6),
    START_DT VARCHAR2(11),
    CANDIDATE MER_OFF_CANDIDATE_t
    CREATE OR REPLACE TYPE MER_OFFER_ACT_DATA_t
    AS
    TABLE OF MER_OFFER_ACT_DATA;
    CREATE OR REPLACE type MER_OFFER_ACTION_DATA
    AS
    OBJECT
    MER_OFF_ACT_DATA MER_OFFER_ACT_DATA_t
    /+
    My Declaration
         +merOffActDataXML          xmltype;
         merOffActData          MER_OFFER_ACTION_DATA := MER_OFFER_ACTION_DATA(MER_OFFER_ACT_DATA_t());+
    Inside Pl/SQL block
         +-- Converts XML data into user defined type for further processing of data
         xmltype.toobject(merOffActDataXML,merOffActData);+
    Thanks for your help
    Beda
    Edited by: Bedabrata Patel on Jul 12, 2010 5:51 AM

    Bedabrata Patel wrote:
    Below are the details:The details except for a description of the problem
    I am facing a problem creating a appropriate a object type for a XML.And which error you are getting
    Error in creation of Object Type http://download.oracle.com/docs/cd/E11882_01/server.112/e10880/toc.htm
    And which version of Oracle you are getting the unknown error creating the unknown problem.

  • ORA-30936: Maximum number of XML node elements exceeded

    I get this error on XmlType.toObject applied to a valid Xml instance (verified outside XmlDb)
    When repeating the test on various documents, the error message always refers to the first child node of the root element, even an attribute, for which maxOccurs is meaningless.
    The instance is provided via HttpUriType.getBLob and UTF-8 encoding.
    Help highly appreciated !
    Robert.

    Found a workaround: insert Xml instance into XmlType table, then toObject after select is OK !
    Probably character set encoding issue.

  • 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

  • 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.
    :-)

  • [Oracle 11g] Store filename as VARCHAR2 and its content as XMLType

    Hi all,
    The version of Oracle used is 11.2.0.3.0.
    I would like to load a XML file into a table from AIX with a Shell script.
    Here is the test case table:
    ALTER  TABLE mytable DROP PRIMARY KEY CASCADE;
    DROP   TABLE mytable CASCADE CONSTRAINTS;
    CREATE TABLE mytable (
       filename VARCHAR2 (50 BYTE),
       created DATE,
       content SYS.XMLTYPE,
       CONSTRAINT pk_mytable PRIMARY KEY (filename) USING INDEX
    XMLTYPE content STORE AS BINARY XML;The problem is to store the the file name too.
    So I add a step to create the control file from a generic one like this:
    #!/bin/ksh
    FILES=$(sample.xml)
    CTL=generic.CTL
    for f in $FILES
    do
        cat $CTL | sed -e "s/:FILE/$f/g" > $f.ctl
        sqlldr scott/tiger@mydb control=$f.ctl data=$f
        rc=$?
        echo "Return code: $rc."
    doneThe filename and the data are stored in the table, but I get this error message after executing the Shell script:
    SQL*Loader: Release 11.2.0.3.0 - Production on Mon Jun 11 13:42:21 2012
    Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.
    SQL*Loader-275: Data is in control file but "INFILE *" has not been specified.
    Commit point reached - logical record count 64And here is the content of the log file:
    SQL*Loader: Release 11.2.0.3.0 - Production on Mon Jun 11 14:13:43 2012
    Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.
    SQL*Loader-275: Data is in control file but "INFILE *" has not been specified.
    Control File:   sample.ctl
    Data File:      sample.xml
      Bad File:     sample.bad
      Discard File:  none specified
    (Allow all discards)
    Number to load: ALL
    Number to skip: 0
    Errors allowed: 50
    Bind array:     64 rows, maximum of 256000 bytes
    Continuation:    none specified
    Path used:      Conventional
    Table MYTABLE, loaded from every logical record.
    Insert option in effect for this table: APPEND
       Column Name                  Position   Len  Term Encl Datatype
    FILENAME                                                  CONSTANT
        Value is 'sample.xml'
    CONTENT                           DERIVED     *  EOF      CHARACTER
        Dynamic LOBFILE.  Filename in field FILENAME
    Record 2: Rejected - Error on table MYTABLE.
    ORA-00001: unique constraint (PK_MYTABLE) violated
    Record 3: Rejected - Error on table MYTABLE.
    ORA-00001: unique constraint (PK_MYTABLE) violated
    Record 4: Rejected - Error on table MYTABLE.
    ORA-00001: unique constraint (PK_MYTABLE) violated
    Record 5: Rejected - Error on table MYTABLE.
    ORA-00001: unique constraint (PK_MYTABLE) violated
    and so on...
    Record 52: Rejected - Error on table MYTABLE.
    ORA-00001: unique constraint (PK_MYTABLE) violated
    MAXIMUM ERROR COUNT EXCEEDED - Above statistics reflect partial run.
    Table MYTABLE:
      1 Row successfully loaded.
      51 Rows not loaded due to data errors.
      0 Rows not loaded because all WHEN clauses were failed.
      0 Rows not loaded because all fields were null.
    Space allocated for bind array:                   1664 bytes(64 rows)
    Read   buffer bytes: 1048576
    Total logical records skipped:          0
    Total logical records read:            64
    Total logical records rejected:        51
    Total logical records discarded:        0
    Run began on Mon Jun 11 14:13:43 2012
    Run ended on Mon Jun 11 14:13:43 2012
    Elapsed time was:     00:00:00.23
    CPU time was:         7586:56:08.38It seems that the control file try to insert as many rows than the number of lines in the file sample.xml !!!
    So, I cannot check if load is done correctly since return code is allways 2!
    Is it the correct way to solve my problem ?
    What can I do to get it better ?

    Another question !
    Here is an other way of doing it.
    #!/bin/ksh
    FILEPATH=./data/sample.xml
    FILENAME=$(basename ${FILEPATH})
    CTLFILE=load_data.ctl
    cat > ${CTLFILE} <<EOF
    LOAD DATA
    INFILE *
    INTO TABLE mytable APPEND
        filename CONSTANT "${FILEPATH}",
        created "SYSDATE",
        content LOBFILE (filename) TERMINATED BY EOF
    BEGINDATA
    ${FILEPATH}
    EOF
    sqlldr scott/tiger@mydb control=${CTLFILE}
    rc=$?
    echo "Return code: $rc."I've tested this script, it's okay.
    Now I want to store the basename of the file : ${FILENAME}.
    How can I do that ?
    The problem is that I can no more write "LOBFILE (filename)" because it does not point to the correct path of the file !!!
    Someone can help me please ?
    Thanks.

Maybe you are looking for

  • How can I update the apps. with the new iTune, that's really silly especially I have two iTune account for different countries

    I used 2 iPhones and a iPad, 2 Apple ID for different countries so that I can download apps. from different country.  Its a pain and sometimes no possible to update the apps. on the ISO devices.  Apple really needs to fix this aspect.  Also the new i

  • Downloading dvd

    I just purchased a mac pro, and have downloaded a dvd video which I created with a tivo dvr system. The dvd will play with idvd, but I can't get the video to open in idvd, or with final cut express, as they will not recognize that file format. Any su

  • Update Multiple Rows using Row Selector

    Hi, I want to update multiple rows using a tabular form with row selector, and an item in another region of the page, using an update expression and a button. The syntax would be like this: update MY_TABLE set UPDATABLE_COLUMN = :P10_NEW_VALUE where

  • What to do if there is no relavent BADI/EXIT for standard transaction

    Hi, Can any one say,What to do if there is no relavent BADI/EXIT for standard transaction. Helpful Answer will be rewarded.

  • Render Files Offline

    I am using Final Cut Pro 7 and each time I open the project Render Files show as offline and no matter how much I try I cannot reconnect them, cannot find them. I have the main folder for the project and I am the only editor using this computer yet i