Removing tags and joining xml to a relational table

db ver 11.2
New to do the whole XML thing so trying hard to figure it out.
I want to join from cdata value to a relational table
the XML is
<?xml version="1.0"?>
<ROWSET>
<ROW>
  <RN>1</RN>
  <EMP_ROW>
   <EMP_ROW_ROW>
    <FNAME>pete</FNAME>
    <ADDRESS>x1 rd</ADDRESS>
   </EMP_ROW_ROW>
   <EMP_ROW_ROW>
    <FNAME>pete</FNAME>
    <ADDRESS>x1 rd</ADDRESS>
   </EMP_ROW_ROW>
   <EMP_ROW_ROW>
    <FNAME>pete2</FNAME>
    <ADDRESS>x2 rd</ADDRESS>
   </EMP_ROW_ROW>
   <EMP_ROW_ROW>
    <FNAME>pete3</FNAME>
    <ADDRESS>x4 rd</ADDRESS>
   </EMP_ROW_ROW>
   <EMP_ROW_ROW>
    <FNAME>pete</FNAME>
   </EMP_ROW_ROW>
   <EMP_ROW_ROW>
    <FNAME>pete3</FNAME>
    <ADDRESS>x4 rd</ADDRESS>
   </EMP_ROW_ROW>
  </EMP_ROW>
</ROW>
<ROW>
  <RN>2</RN>
  <EMP_ROW>
   <EMP_ROW_ROW>
    <FNAME>pete</FNAME>
   </EMP_ROW_ROW>
  </EMP_ROW>
</ROW>
<ROW>
  <RN>3</RN>
  <EMP_ROW>
   <EMP_ROW_ROW>
    <FNAME>pete3</FNAME>
    <ADDRESS>x4 rd</ADDRESS>
   </EMP_ROW_ROW>
  </EMP_ROW>
</ROW>
<ROW>
  <RN>4</RN>
  <EMP_ROW>
   <EMP_ROW_ROW>
    <FNAME>pete4</FNAME>
    <ADDRESS>a str</ADDRESS>
   </EMP_ROW_ROW>
   <EMP_ROW_ROW>
    <FNAME>pete3</FNAME>
    <ADDRESS>b str</ADDRESS>
   </EMP_ROW_ROW>
  </EMP_ROW>
</ROW>
<ROW>
  <RN>5</RN>
  <EMP_ROW>
   <EMP_ROW_ROW>
    <FNAME>bob1</FNAME>
    <ADDRESS>c str</ADDRESS>
   </EMP_ROW_ROW>
  </EMP_ROW>
</ROW>
<ROW>
  <RN>6</RN>
  <EMP_ROW>
  </EMP_ROW>
</ROW>
<ROW>
  <RN>7</RN>
  <EMP_ROW>
  </EMP_ROW>
</ROW>
<ROW>
  <RN>8</RN>
  <EMP_ROW>
  </EMP_ROW>
</ROW>
<ROW>
  <RN>9</RN>
  <EMP_ROW>
  </EMP_ROW>
</ROW>
<ROW>
  <RN>10</RN>
  <EMP_ROW>
  </EMP_ROW>
</ROW>
<ROW>
  <RN>11</RN>
  <EMP_ROW>
  </EMP_ROW>
</ROW>
<ROW>
  <RN>12</RN>
  <EMP_ROW>
  </EMP_ROW>
</ROW>
<ROW>
  <RN>13</RN>
  <EMP_ROW>
  </EMP_ROW>
</ROW>
<ROW>
  <RN>14</RN>
  <EMP_ROW>
  </EMP_ROW>
</ROW>
<ROW>
  <RN>15</RN>
  <EMP_ROW>
  </EMP_ROW>
</ROW>
<ROW>
  <RN>16</RN>
  <EMP_ROW>
  </EMP_ROW>
</ROW>
<ROW>
  <RN>17</RN>
  <EMP_ROW>
  </EMP_ROW>
</ROW>
<ROW>
  <RN>18</RN>
  <EMP_ROW>
  </EMP_ROW>
</ROW>
<ROW>
  <RN>19</RN>
  <EMP_ROW>
  </EMP_ROW>
</ROW>
<ROW>
  <RN>20</RN>
  <EMP_ROW>
  </EMP_ROW>
</ROW>
</ROWSET>the relational table is:
create table t(
rn  number primary key
with 20 rows 1 to 20the results should be in a relational table
RN               XML
1        <EMP_ROW>
          <EMP_ROW_ROW>
        <FNAME>pete</FNAME>
       <ADDRESS>x1 rd</ADDRESS>
     </EMP_ROW_ROW>
   <EMP_ROW_ROW>
    <FNAME>pete</FNAME>
    <ADDRESS>x1 rd</ADDRESS>
   </EMP_ROW_ROW>
   <EMP_ROW_ROW>
    <FNAME>pete2</FNAME>
    <ADDRESS>x2 rd</ADDRESS>
   </EMP_ROW_ROW>
     <EMP_ROW_ROW>
      <FNAME>pete3</FNAME>
      <ADDRESS>x4 rd</ADDRESS>
     </EMP_ROW_ROW>
     <EMP_ROW_ROW>
      <FNAME>pete</FNAME>
     </EMP_ROW_ROW>
     <EMP_ROW_ROW>
      <FNAME>pete3</FNAME>
      <ADDRESS>x4 rd</ADDRESS>
     </EMP_ROW_ROW>
    </EMP_ROW>
2       <EMP_ROW>
   <EMP_ROW_ROW>
    <FNAME>pete</FNAME>
   </EMP_ROW_ROW>
  </EMP_ROW>I am wanting to join on the <RN> to the RN in the relational table.
Been trying at this for a bit .. seems like xmltable and xquery should get me there but have problems.

I guess since there are many and duplicate <RN> in the XML the function returns one row
<RN>1</RN><RN>2</RN><RN>3</RN><RN>4</RN><RN>5</RN><RN>6</RN><RN>7</RN><RN>8</RN><RN>9</RN><RN>10</RN><RN>11</RN><RN>12</RN><RN>13</RN><RN>14</RN><RN>15</RN><RN>16</RN><RN>17</RN><RN>18</RN><RN>19</RN><RN>20</RN>     "<?xml version="1.0"?>
<ROWSET>
<ROW>
  <RN>1</RN>
  <EMP_ROW>
   <EMP_ROW_ROW>
    <FNAME>pete</FNAME>
    <ADDRESS>x1 rd</ADDRESS>
   </EMP_ROW_ROW>
   <EMP_ROW_ROW>
    <FNAME>pete</FNAME>
    <ADDRESS>x1 rd</ADDRESS>
   </EMP_ROW_ROW>
   <EMP_ROW_ROW>
    <FNAME>pete2</FNAME>
    <ADDRESS>x2 rd</ADDRESS>
   </EMP_ROW_ROW>
   <EMP_ROW_ROW>
    <FNAME>pete3</FNAME>
    <ADDRESS>x4 rd</ADDRESS>
   </EMP_ROW_ROW>
   <EMP_ROW_ROW>
    <FNAME>pete</FNAME>
   </EMP_ROW_ROW>
   <EMP_ROW_ROW>
    <FNAME>pete3</FNAME>
    <ADDRESS>x4 rd</ADDRESS>
   </EMP_ROW_ROW>
  </EMP_ROW>
</ROW>
<ROW>
  <RN>2</RN>
  <EMP_ROW>
   <EMP_ROW_ROW>
    <FNAME>pete</FNAME>
   </EMP_ROW_ROW>
  </EMP_ROW>
</ROW>
<ROW>
  <RN>3</RN>
  <EMP_ROW>
   <EMP_ROW_ROW>
    <FNAME>pete3</FNAME>
    <ADDRESS>x4 rd</ADDRESS>
   </EMP_ROW_ROW>
  </EMP_ROW>
</ROW>
<ROW>
  <RN>4</RN>
  <EMP_ROW>
   <EMP_ROW_ROW>
    <FNAME>pete4</FNAME>
    <ADDRESS>a str</ADDRESS>
   </EMP_ROW_ROW>
   <EMP_ROW_ROW>
    <FNAME>pete3</FNAME>
    <ADDRESS>b str</ADDRESS>
   </EMP_ROW_ROW>
  </EMP_ROW>
</ROW>
<ROW>
  <RN>5</RN>
  <EMP_ROW>
   <EMP_ROW_ROW>
    <FNAME>bob1</FNAME>
    <ADDRESS>c str</ADDRESS>
   </EMP_ROW_ROW>
  </EMP_ROW>
</ROW>
<ROW>
  <RN>6</RN>
  <EMP_ROW>
  </EMP_ROW>
</ROW>
<ROW>
  <RN>7</RN>
  <EMP_ROW>
  </EMP_ROW>
</ROW>
<ROW>
  <RN>8</RN>
  <EMP_ROW>
  </EMP_ROW>
</ROW>
<ROW>
  <RN>9</RN>
  <EMP_ROW>
  </EMP_ROW>
</ROW>
<ROW>
  <RN>10</RN>
  <EMP_ROW>
  </EMP_ROW>
</ROW>
<ROW>
  <RN>11</RN>
  <EMP_ROW>
  </EMP_ROW>
</ROW>
<ROW>
  <RN>12</RN>
  <EMP_ROW>
  </EMP_ROW>
</ROW>
<ROW>
  <RN>13</RN>
  <EMP_ROW>
  </EMP_ROW>
</ROW>
<ROW>
  <RN>14</RN>
  <EMP_ROW>
  </EMP_ROW>
</ROW>
<ROW>
  <RN>15</RN>
  <EMP_ROW>
  </EMP_ROW>
</ROW>
<ROW>
  <RN>16</RN>
  <EMP_ROW>
  </EMP_ROW>
</ROW>
<ROW>
  <RN>17</RN>
  <EMP_ROW>
  </EMP_ROW>
</ROW>
<ROW>
  <RN>18</RN>
  <EMP_ROW>
  </EMP_ROW>
</ROW>
<ROW>
  <RN>19</RN>
  <EMP_ROW>
  </EMP_ROW>
</ROW>
<ROW>
  <RN>20</RN>
  <EMP_ROW>
  </EMP_ROW>
</ROW>
</ROWSET>
"

Similar Messages

  • Mapping with xml-schema XML-data to relational tables

    Hello,
    is it possible to map data from xml documents to relational tables with xml-schema?
    I mean not in nested tables but in relational tables with primary and foreign keys!
    With SQL Server 2005 it is very easy, I dont believe that Oracle couldn't do this!
    I searched but i cant find anything about that!
    Thx
    user445232

    indeed, oracle does this for xml schema based xmltype data, however, these underlying tables are not accessable to the application. Maybe It should for next version, so folks who like to use relational model can use it without mapping it manually.
    Actually, nested tables, are the same, their underlying tables (segments) are indeed relational tables, oracle manages them internally and not visiable to the application. You can find them in the user_segments, user_objects views though.

  • Generate xml from non-relational table

    Hi
    I would like to create hierarchical xml from non-relational table as below, can anybody share some idea?
    I have tried the XMLAgg/XmlElement and could not get the desired result. Any help would be greately appreciated.
    create table testing
    ( super_cat varchar2(30)
    , normal_cat varchar2(30)
    , sub_cat varchar2(30)
    , detail varchar2(30));
    CREATE UNIQUE INDEX IDX_TESTING ON TESTING(SUPER_CAT,NORMAL_CAT,SUB_CAT);
    insert into testing values ('SUPER_A','NORMAL_A','SUB_A', 'DETAIL1');
    insert into testing values ('SUPER_A','NORMAL_A','SUB_B', 'DETAIL2');
    insert into testing values ('SUPER_A','NORMAL_B','SUB_A', 'DETAIL3');
    insert into testing values ('SUPER_A','NORMAL_B','SUB_B', 'DETAIL4');
    COMMIT;The result should be like :
    <Document>
    <SuperCategory>
    <SuperCategoryName>SUPER_A</SuperCategoryName>
    <NormalCategory>
    <NormalCategoryName>NORMAL_A</NormalCategoryName>
    <SubCategory>
    <SubCategoryName>SUB_A</SubCategoryName>
    <ResultDetail><Detail>DETAIL1</Detail></ResultDetail>
    </SubCategory>
    <SubCategory>
    <SubCategoryName>SUB_B</SubCategoryName>
    <ResultDetail><Detail>DETAIL2</Detail></ResultDetail>
    </SubCategory>
    </NormalCategory>
    <NormalCategory>
    <NormalCategoryName>NORMAL_B</NormalCategoryName>
    <SubCategory>
    <SubCategoryName>SUB_A</SubCategoryName>
    <ResultDetail><Detail>DETAIL3</Detail></ResultDetail>
    </SubCategory>
    <SubCategory>
    <SubCategoryName>SUB_B</SubCategoryName>
    <ResultDetail><Detail>DETAIL4</Detail></ResultDetail>
    </SubCategory>
    </NormalCategory>
    </SuperCategory>
    </Document>

    user563940 wrote:
    Hi
    I would like to create hierarchical xml from non-relational table as below, can anybody share some idea?
    I have tried the XMLAgg/XmlElement and could not get the desired result. Any help would be greately appreciated.I think you should be able to achieve this with the addition of XMLFOREST.
    http://download.oracle.com/docs/cd/E11882_01/server.112/e17118/functions244.htm#SQLRF06169

  • How to create xml file from relational tables in 10gR2

    Hi,
    I am very new to XML and was wondering how to create an XML file from querying relational tables. Some child tables may contain multiple rows that need to be returned in certain instances. Other queries will just be single or multiple rows from one or more tables. I would like to use the latest feathers in 10gR2. Thanks for any help you can provide.
    Thanks,
    Lee

    Here is the first row of data created from our person table - it used the column names as the tag names:
    <?xml version="1.0"?>
    <ROWSET>
         <ROW>
              <MP_ID_SEQ>289</MP_ID_SEQ>
              <MP_NAME>LOBERG,JUDITH LEE</MP_NAME>
              <MP_SEX>F</MP_SEX>
              <MP_RACE>I</MP_RACE>
              <MP_DOB>19500709</MP_DOB>
              <MP_HT>504</MP_HT>
              <MP_WT>170</MP_WT>
              <MP_EYE_CLR>BLU</MP_EYE_CLR>
              <MP_HAIR_CLR>BRO</MP_HAIR_CLR>
              <MP_SKN>RUD</MP_SKN>
              <MP_SMT>POCKMARKS</MP_SMT>
              <MP_SOC>517607968</MP_SOC>
              <MP_OLN>517607968</MP_OLN>
              <MP_OLS>MT</MP_OLS>
              <MP_OLY>2007</MP_OLY>
              <MP_CAUT_MED>70</MP_CAUT_MED>
              <MP_VISION_SCRIPT>C0RRECTIVE LENSES</MP_VISION_SCRIPT>
              <MP_DNA_AVAIL>N</MP_DNA_AVAIL>
              <CREATED_BY>MMPS</CREATED_BY>
              <DTM_CREATED>31-AUG-06</DTM_CREATED>
              <MI_INC_ID_SEQ>288</MI_INC_ID_SEQ>
              <MP_ALERT>N</MP_ALERT>
         </ROW>

  • Loading XML Data into Relational Table

    Hello,
    I receive an XML file generated from another tool (on Windows), I am trying to create a Linux shell script that will gather the needed XML file from my Linux database server, then have Oracle use this file to load the XML data into a relational table. This activity & data will be needed on an ongoing basis.
    I have tried this two ways. First, I loaded the XML document into the database and tried to extract the data directly from the document, but that is not working. Now I want to try to read the data directly from the file on the server via select, however I am not getting any data returned. In the Select statement below, I am simply trying to query the data to see what is returned for my testing.
    Create Table ci_results_table (transactionID Varchar2(100), //transactionID should be PrimaryKey but was getting NULL value errors during insert test, so removed PK
    message Varchar2(200),
    ci Varchar2(50),
    processeddate xmltype,
    status Varchar2(50),
    sourcefile VarChar2(100));
    select x.*
    from XMLTable(
         'TSPLoadResults/Results'
         PASSING xmltype(bfilename('CMDB_DEVADHOCRESULTS_DIR','LoadResults-HP_146.results.xml'), nls_charset_id('AL32UTF8'))
         COLUMNS
           transactionID Varchar2(100) PATH 'TransactionID',
           Result XMLType PATH 'Result',
           Message Varchar2(200) PATH 'Message',
           PrimaryKey Varchar2(50) PATH 'PrimaryKey',
           ProcessedDate date PATH 'ProcessedDate',
           Status Varchar2(50) PATH 'Status',
           SourceFile VarChar2(100) PATH 'SourceFileName'
       ) x
    Eventually I will need to build on this to limit the data returned to those records where SourceFileName is like 'HPDS%' and insert what is returned in to the ci_results_table. Attached is a sample Results XML file I am trying to load, It is named "ResultsTransformedtoUnix" because I used dos2Unix to convert it to Unix which may be right or wrong. (The output file I send out has to be transformed to DOS format before the other application can read it). Original file (before Unix conversion) named in script is also attached.
    Please help. Thank you!

    Hi,
    I see some wrong things in your query.
    1) The obvious one, explaining why you're not getting any data : there's a typo in the XQuery expression, it's "Result" not "Results"
    2) ProcessedDate cannot be extracted as a date (at least not directly) since it actually represents a timestamp, use TIMESTAMP WITH TIME ZONE datatype and cast back to DATE in the SELECT clause
    3) transactionID is an attribute, it must be accessed with '@' (or 'attribute::' axis)
    4) If the file encoding is truly ISO-8859-1 as the prolog suggests, then do not use AL32UTF8 but the corresponding charset name : WE8ISO8859P1
    Here's the working query :
    select x.transactionID
         , x.Message
         , x.Primarykey
         , cast(x.ProcessedDate as date) ProcessDate
         , x.Status
         , x.SourceFile
    from XMLTable(
           '/TSPLoadResults/Result'
           PASSING xmltype(bfilename('XML_DIR','LoadResults-HP_146.results.xml'), nls_charset_id('WE8ISO8859P1'))
           COLUMNS
             transactionID Varchar2(100)            PATH '@transactionID',
             Message       Varchar2(200)            PATH 'Message',
             PrimaryKey    Varchar2(50)             PATH 'PrimaryKey',
             ProcessedDate timestamp with time zone PATH 'ProcessedDate',
             Status        Varchar2(50)             PATH 'Status',
             SourceFile    VarChar2(100)            PATH 'SourceFileName'
         ) x
    Using this query directly over the file will only perform decently (for large files) on 11.2.0.4 and onwards.
    On prior versions, first load the file in a (temporary) XMLType column with Binary XML storage and SELECT from there.
    because I used dos2Unix to convert it to Unix which may be right or wrong.
    This conversion shouldn't be necessary.

  • XML Data from Relational Tables

    Hi,
    My requirement is to pull data from relational tables into xml format and port it to the user (either as a file or allow the user to access it directly from their browser). What is the best way to accomplish this. Your suggestions are appreciated.
    thanks.

    Marco,
    Thanks for your reply, did try that , but I want the users to query this view also. Due to the nature of the xml structure I am getting the correct results. May be my xpath query is not right? My xml is as below:
    <node1 attribute-node1 = "somevalue1">
    <cnode1 attribute-cnode1 = "somevalue2">
    <cnode2 attribute-cnode2 = "somevalue3">
    <cnode3>somevalue4</cnode3>
    <cnode4>somevalue5</cnode4>
    </cnode2>
    <cnode2 attribute-cnode2 = "somevlaue6">
    <cnode3>somevalue6</cnode3>
    <cnode4>somevalue7</cnode4>
    </cnode2>
    </cnode1>
    </node1>
    and my requirement is like : the user wants to see only cnode2 with attribute value "somevalue3" (along with the rest of the xml) ie
    <node1 attribute-node1 = "somevalue1">
    <cnode1 attribute-cnode1 = "somevalue2">
    <cnode2 attribute-cnode2 = "somevalue3">
    <cnode3>somevalue4</cnode3>
    <cnode4>somevalue5</cnode4>
    </cnode2>
    </cnode1>
    </node1>
    Need the correct xpath query for this.
    Thanks

  • XML DB to Relational table?

    Hi Everybody,
    We have a situation to map the elements/attributes of XML tables in XML DB (Oracle 9i) to target relational tables.
    We have XML schema as starting point. Do you have any white paper or documentation to help us do mapping ?
    I appreciate your help.
    Ram

    You can start from here:
    http://otn.oracle.com/tech/xml/xmldb/index.html

  • How to make optimizer fetch and join values from Indexes, no table access.

    Hi All,
    i am having a query which is just checking the existence of the values according to some of the filter criteria, and involves two tables in join. and i want optimizer to find the existence i.e the reult of the query by only accessing indexes only, not to go through table scan using indexes. Is there any way so that i can modify my query or force the optimizer to do the same? below is the existing plan of the query in which its accessing tables using indexes, which causing bottleneck in my DB as these tables are bulky ones.
    Execution Plan
    Plan hash value: 1209914516
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop |
    | 0 | SELECT STATEMENT | | 1 | | 6 (17)| 00:00:01 | | |
    | 1 | SORT AGGREGATE | | 1 | | | | | |
    |* 2 | FILTER | | | | | | | |
    | 3 | FAST DUAL | | 1 | | 2 (0)| 00:00:01 | | |
    | 4 | NESTED LOOPS | | 1 | 24 | 4 (25)| 00:00:01 | | |
    | 5 | SORT UNIQUE | | 1 | 10 | 2 (0)| 00:00:01 | | |
    | 6 | TABLE ACCESS BY INDEX ROWID | INVOICELINEDISB | 1 | 10 | 2 (0)| 00:00:01 | | |
    |* 7 | INDEX RANGE SCAN | IDX_INVLINEDISB_UOMCD | 1 | | 1 (0)| 00:00:01 | | |
    | 8 | PARTITION HASH ITERATOR | | 1 | 14 | 1 (0)| 00:00:01 | KEY | KEY |
    |* 9 | TABLE ACCESS BY GLOBAL INDEX ROWID| INVOICEHEADERDISB | 1 | 14 | 1 (0)| 00:00:01 | ROWID | ROWID |
    |* 10 | INDEX UNIQUE SCAN | P_INVOICEHEADERDISB_PART | 1 | | 0 (0)| 00:00:01 | KEY | KEY |
    Predicate Information (identified by operation id):
    2 - filter( EXISTS (SELECT 0 FROM "XIGNCMN"."INVOICEHEADERDISB" "INVOICEHEADERDISB","XIGNCMN"."INVOICELINEDISB"
    "INVOICELINEDISB" WHERE "INVOICELINEDISB"."UNITOFMEASURECD"='USD' AND
    "INVOICEHEADERDISB"."INVOICEPK"="INVOICELINEDISB"."INVOICEPK" AND "INVOICEHEADERDISB"."PAYPK"=8135488395))
    7 - access("INVOICELINEDISB"."UNITOFMEASURECD"='USD')
    9 - filter("INVOICEHEADERDISB"."PAYPK"=8135488395)
    10 - access("INVOICEHEADERDISB"."INVOICEPK"="INVOICELINEDISB"."INVOICEPK")
    Statistics
    0 recursive calls
    0 db block gets
    14 consistent gets
    0 physical reads
    0 redo size
    410 bytes sent via SQL*Net to client
    385 bytes received via SQL*Net from client

    Jonathan Lewis wrote:
    930254 wrote:
    Hi All,
    i am having a query which is just checking the existence of the values according to some of the filter criteria, and involves two tables in join. and i want optimizer to find the existence i.e the reult of the query by only accessing indexes only, not to go through table scan using indexes. Is there any way so that i can modify my query or force the optimizer to do the same? below is the existing plan of the query in which its accessing tables using indexes, which causing bottleneck in my DB as these tables are bulky ones.
    Execution Plan
    Plan hash value: 1209914516
    | Id  | Operation                              | Name                     | Rows  | Bytes | Cost (%CPU)| Time     | Pstart| Pstop |
    |   0 | SELECT STATEMENT                       |                          |     1 |       |     6  (17)| 00:00:01 |       |       |
    |   1 |  SORT AGGREGATE                        |                          |     1 |       |            |          |       |       |
    |*  2 |   FILTER                               |                          |       |       |            |          |       |       |
    |   3 |    FAST DUAL                           |                          |     1 |       |     2   (0)| 00:00:01 |       |       |
    |   4 |    NESTED LOOPS                        |                          |     1 |    24 |     4  (25)| 00:00:01 |       |       |
    |   5 |     SORT UNIQUE                        |                          |     1 |    10 |     2   (0)| 00:00:01 |       |       |
    |   6 |      TABLE ACCESS BY INDEX ROWID       | INVOICELINEDISB          |     1 |    10 |     2   (0)| 00:00:01 |       |       |
    |*  7 |       INDEX RANGE SCAN                 | IDX_INVLINEDISB_UOMCD    |     1 |       |     1   (0)| 00:00:01 |       |       |
    |   8 |     PARTITION HASH ITERATOR            |                          |     1 |    14 |     1   (0)| 00:00:01 |   KEY |   KEY |
    |*  9 |      TABLE ACCESS BY GLOBAL INDEX ROWID| INVOICEHEADERDISB        |     1 |    14 |     1   (0)| 00:00:01 | ROWID | ROWID |
    |* 10 |       INDEX UNIQUE SCAN                | P_INVOICEHEADERDISB_PART |     1 |       |     0   (0)| 00:00:01 |   KEY |   KEY |
    Predicate Information (identified by operation id):
    2 - filter( EXISTS (SELECT 0 FROM "XIGNCMN"."INVOICEHEADERDISB" "INVOICEHEADERDISB","XIGNCMN"."INVOICELINEDISB"
    "INVOICELINEDISB" WHERE "INVOICELINEDISB"."UNITOFMEASURECD"='USD' AND
    "INVOICEHEADERDISB"."INVOICEPK"="INVOICELINEDISB"."INVOICEPK" AND "INVOICEHEADERDISB"."PAYPK"=8135488395))
    7 - access("INVOICELINEDISB"."UNITOFMEASURECD"='USD')
    9 - filter("INVOICEHEADERDISB"."PAYPK"=8135488395)
    10 - access("INVOICEHEADERDISB"."INVOICEPK"="INVOICELINEDISB"."INVOICEPK")
    The sort unique at line 5 is surprising, I can't think of an obvious reason why it should appear unless the optimizer is trying to do something very clever to work around a problem we can't see (such as a statistics error with the hash partitioned indexe).
    Assuming that the test would do better starting with invoiceheaderdisn.paypkl I have to ask if you have an index on INVOICELINEDISB(INVOICEPK).The optimizer's choice of driving table indeed looks odd. Could it be due to misleading statistics or plain bug or just a case of CBO preferring a non-partitioned table over partitioned table when deciding the driving table? I must admit this design does look odd as it appears INVOICEHEADERDISB is a parent table and INVOICELINEDISB is a child table but somehow the parent table has been partitioned (using hash partitioning, I assume) but the child table is not.
    However, once CBO has decided the driving table, the SORT UNIQUE is not quite surprising. Assuming optimizer knows that there is a parent-child relationship between INVOICEHEADERDISB and INVOICELINEDISB table (based on INVOICEPK column), CBO needs to access only INVOICEPK and UNITOFMEASURECD columns fron the INVOICELINEDISB table in order to process the join. It uses index range scan on UNITOFMEASURECD table in order to get (part of) the necessary data and then accesses INVOICELINEDISB table to get the values of INVOICEPK column. Being a child table, it is possible that the driving row source will contain duplicate values for INVOICEPK column but not necessarily sorted. As CBO knows that outer table (i.e. INVOICEHEADERDISB) has a PK on INVOICEPK column, each row in driving row source will have either 1 or 0 rows matching from outer table. It appears that CBO "decides" that by eliminating the duplicate values of the INVOICEPK from driving row source, it can reduce the number of times the INVOICEHEADERDISB table is accessed.
    Now I am not sure if CBO does all this (eliminating duplicates from driving row source) only because the outer table is partitioned.
    Coming back to OP's original question, I believe OP will have to change the index definitions in order to avoid table access for this query. But there has to be a strong and logical argument to make this kind of change for just one query.
    Hope this helps.

  • Remove tag item from xml

    Hi there,
    Iu2019ve created a program  to generate a xml file, using SDIXML_DATA_TO_DOM function. However it seems that is not working correctly because it generates an extra tag, that is called ITEM, whenever there is a table. However, every program example's that use that function, also generates that tag. Is it possible, somehow, remove it?
    Many thanks,
    Helena

    Helena:
    Actually I don't think it's wrong...
    <DOCID>
    <ITEM>
    <TYPE>AR</TYPE>
    <NUMBER>1236544</NUMBER>
    </ITEM>
    <ITEM>
    <TYPE>BI</TYPE>
    <NUMBER>1254666</NUMBER>
    </ITEM>
    </DOCID>
    Here, <ITEM></ITEM> is being used to clearly separate <TYPE> and <NUMBER> by grouping them...<DOCID> is the main parent tag, so you can't have what you want...You should generate separate XML files for each group...Like...
    <DOCID>
    <TYPE>AR</TYPE>
    <NUMBER>1236544</NUMBER>
    </DOCID>
    <DOCID>
    <TYPE>BI</TYPE>
    <NUMBER>1254666</NUMBER>
    </DOCID>
    Greetings,
    Blag.

  • Load XML Data into relational Table

    Hi All,
    I have a requirement to load data in an XML file into columns in an oracle table. This has to be done on the command line from a unix box which connects to a remote oracle DB.
    Can some one give me a step by step procedure to do this (preferably using sqlloader) or point me in the right direction.
    thank you

    Hi,
    Read "Oracle XML DB Developer's guide", Chapters 2,3,4,5.
    That will give you very good idea.
    The reason, I am suggesting reading is, there is not "one" way to do it. There can be many good ways, depending on the size, complexity of the XML and also your intended use of that XML data.
    Regards

  • Create a large XML extract from relational tables - 10g

    The Oracle 10g documentation recommends using the various SQL functions such as XMLAGG,XMLELEMENT or DBMS_XMLGEN under chapter "16 Generating XML Data from the Database" for generating a XML extract file. The DBMS_XMLDOM seems like a useful structured package to create a XML formatted extract. Any idea why Oracle does not recommend the use of XMLDOM API ? Are there performance issues or likely de-support ?
    Whats the best way to produce a large XML extract?
    Thanks.

    mdrake wrote:
    No reason not to use it. It just tends to require a lot more coding than the other methods. Underneath the covers they all map into the same code-line. In general, to generate a given XML document you wlll write far fewer lines of code using the SQL/XML operators. Less Code written = less code to maintan = faster time to market.Less code to parse...?

  • XML file validation with XSD and loading to database relational table

    Hi all,
    I have some xml files coming to my unix directory. I will be having an XSD for those. My task is to validate those xml against given xsd and load the corresponding data into oracle relational tables with sqlloader only.
    Please help me to accomplish. and let me know the contents of control file ( for SQLLOADER) if i want to load the xml directly to database.
    Unix and/or PLSQL suggestions both are welcome.

    My problem area is loading the XML to Oracle relational tables using sqlloader.
    suppose, the xml is <?xml version="1.0"?>
    <Customers>
    <Customer>
    <CustID>1</CustID>
    <Company>Bell South</Company>
    <City>New York</City>
    </Customer>
    <Customer>
    <CustID>2</CustID>
    <Company>Barnes &amp; Noble</Company>
    <City>New York</City>
    </Customer>
    <Customer>
    <CustID>3</CustID>
    <Company>Comp USA</Company>
    <City>Tampa</City>
    </Customer>
    <Customer>
    <CustID>4</CustID>
    <Company>Borders</Company>
    <City>Charlotte</City>
    </Customer>
    </Customers>
    and I have a relational table
    CREATE TABLE CUSTOMERS
    CUSTID NUMBER,
    COMPANY VARCHAR2(100 BYTE),
    CITY VARCHAR2(100 BYTE)
    how to insert the xml data into the table???
    please help..
    Edited by: nuon on Oct 25, 2010 6:25 AM

  • Create XML docs with hierarchy of tags and attr defined in databaste tables

    Hi,
    My problem is a little unique one. I want the ability to define the structure of the XML document (i.e. the hierarchy of element tags and attribute names) in the database tables. The values of tags and attributes will also be populated at runtime in tables.
    Then write some generic API that reads the structure of the XML document through the database tables and spits out an XML document based on this structure and values stored in the tables.
    So, basically, I want the tag names and values both to be values in the database rather than the tag names being the columns in database tables.
    With this I should be able to have one procedure/function that can serve the purpose of creating XML documents with different structures by just specifying that structure in the form of database tables.
    Almost all the Oracle XML utilities I read about, create XML docs based on a SQL query with tag names being columns in the database tables. Any help will be highly appreciated.
    Thanks,
    Monika

    Which database release are you using...
    The computed constructors feature of XQuery may help.
    -Mark

  • Nested XML output in relational format

    I have serious performance issue in converting the relational xml in to relational table.
    Below is my query which works good if number of nodes are around <100.
    I have issue if number of node is more then 500.I have requirement where the number of nodes can be >5000.
    I am using Oracle 11g R2.
    Appreciate the help in tuning this or any alternative for this.
    Thanks,
    WITH t1
           AS (SELECT xmltype('<Id_359328 prodId="101265" prodName="Computer">
      <Id_359329  prodId="101788" prodName="C1">
        <Id_359330 prodId="175" prodName="C2"/>
        <Id_359331 prodId="101766" prodName="C3"/>
      </Id_359329>
      <Id_388909 prodId="100654" prodName="C4"/>
      <Id_388191 prodId="100672" prodName="C5"/>
      <Id_388927 prodId="100625" prodName="C6"/>
      <Id_359332 prodId="101766" prodName="C7">
        <Id_359380 prodId="100651" prodName="C8" />
        <Id_359334 prodId="100643" prodName="C9">
          <Id_359337 prodId="101788" prodName="C10">
            <Id_359338 prodId="175" prodName="C11"/>
            <Id_359339 prodId="101766" prodName="C12"/>
          </Id_359337>
        </Id_359334>
        <Id_359336 prodId="101860" prodName="C13"/>
      </Id_359332>
    </Id_359328>')
                         t1_val
               FROM DUAL)
    SELECT ROWNUM rn, id, prod_id, prnt_id
    FROM t1,
         XMLTABLE ('for $i in $doc/descendant::*
                             return <ROW><Id>{name($i)}</Id>
                             <PROD_ID>{data($i/@prodId)}</PROD_ID>
                              <PRNT_ID>{name($i/..)}</PRNT_ID>
                                                    </ROW>'
                      PASSING t1.t1_val AS "doc"
                      COLUMNS id VARCHAR2 (100) PATH '/ROW/Id',
                              prod_id NUMBER PATH '/ROW/PROD_ID',
                              prnt_id VARCHAR2 (100) PATH '/ROW/PRNT_ID'
    ORDER BY ROWNUM
    Output
    RN     ID             PROD_ID     PRNT_ID
    1     Id_359328     101265     
    2     Id_359329     101788     Id_359328
    3     Id_359330     175     Id_359329
    4     Id_359331     101766     Id_359329
    5     Id_388909     100654     Id_359328
    6     Id_388191     100672     Id_359328
    7     Id_388927     100625     Id_359328
    8     Id_359332     101766     Id_359328
    9     Id_359380     100651     Id_359332
    10     Id_359334     100643     Id_359332
    11     Id_359337     101788     Id_359334
    12     Id_359338     175     Id_359337
    13     Id_359339     101766     Id_359337
    14     Id_359336     101860     Id_359332Edited by: ravit on Apr 20, 2010 4:43 PM

    Hi,
    I agree with damorgan, XQuery processing requires some ressources and it could help to have some of your system specs and settings.
    Anyway, tuning is not my specialty but I can give you an alternative.
    You could move the XQuery logic to an XSLT stylesheet and transform the document before passing it to XMLTable.
    For example :
    Creating sample data like yours...
    CREATE TABLE test_tree AS
    SELECT n,
           power(10,p)*(1+trunc(n/power(10,p))) p
    FROM (
      SELECT level n,
             nvl(length(regexp_substr(level,'0+$')),0)+1 p
      FROM dual
      CONNECT BY level < 10000
    UNION ALL
    SELECT 10000, null FROM dual
    CREATE TABLE test_xml (
    doc1 xmltype,
    doc2 xmltype
    DECLARE
    ctx dbms_xmlgen.ctxHandle;
    doc xmltype;
    xsl xmltype := xmltype(
    '<?xml version="1.0"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml"/>
    <xsl:template match="/">
    <root>
      <xsl:apply-templates/>
    </root>
    </xsl:template>
    <xsl:template match="*">
    <ROW Id="{name(.)}">
      <PROD_ID><xsl:value-of select="@prodId"/></PROD_ID>
      <PRNT_ID><xsl:value-of select="name(..)"/></PRNT_ID>
    </ROW>
    <xsl:apply-templates/>
    </xsl:template>
    </xsl:stylesheet>'
    BEGIN
    -- hierarchical XML generation :
    ctx := dbms_xmlgen.newContextFromHierarchy(
    'select level,
             xmlelement(evalname(''Id_''||to_char(n,''fm09999'')),
               xmlattributes( to_char(n) as "prodId",
                              ''C''||to_char(n) as "prodName" )
      from test_tree
      connect by prior n = p
      start with p is null'
    doc := dbms_xmlgen.getXMLType(ctx);
    dbms_xmlgen.closeContext(ctx);
    INSERT INTO test_xml VALUES(doc, doc.transform(xsl));
    COMMIT;
    END;
    /Now, TEST_XML.DOC1 holds the original document, DOC2 holds the result of the transformation :
    <root>
      <ROW Id="Id_10000">
        <PROD_ID>10000</PROD_ID>
        <PRNT_ID>#document</PRNT_ID>
      </ROW>
      <ROW Id="Id_01000">
        <PROD_ID>1000</PROD_ID>
        <PRNT_ID>Id_10000</PRNT_ID>
      </ROW>
      <ROW Id="Id_00100">
        <PROD_ID>100</PROD_ID>
        <PRNT_ID>Id_01000</PRNT_ID>
      </ROW>
      <ROW Id="Id_00010">
        <PROD_ID>10</PROD_ID>
        <PRNT_ID>Id_00100</PRNT_ID>
      </ROW>
      <ROW Id="Id_09997">
        <PROD_ID>9997</PROD_ID>
        <PRNT_ID>Id_10000</PRNT_ID>
      </ROW>
      <ROW Id="Id_09998">
        <PROD_ID>9998</PROD_ID>
        <PRNT_ID>Id_10000</PRNT_ID>
      </ROW>
      <ROW Id="Id_09999">
        <PROD_ID>9999</PROD_ID>
        <PRNT_ID>Id_10000</PRNT_ID>
      </ROW>
    </root>Then we can execute the query on DOC2:
    SELECT rn, id, prod_id, prnt_id
    FROM test_xml x,
         XMLTable(
          '/root/ROW'
          passing x.doc2
          columns
            id      VARCHAR2(100) path '@Id',
            prod_id NUMBER        path 'PROD_ID',
            prnt_id VARCHAR2(100) path 'PRNT_ID',
            rn      FOR ORDINALITY
    ;On my environment, 10000 records fetched in about 18s.

  • "PLS-00172: string literal too long" When Writing XML file into a Table

    Hi.
    I'm using DBMS_XMLStore to get a XML file into a db table. See the example below, I'm using that for my PL/SQL format. Problem is that because there're too many XML elements that I use in "xmldoc CLOB:= ...", I get "PLS-00172: string literal too long" error.
    Can someone suggest a workaround?
    THANKS!!!
    DECLARE
    insCtx DBMS_XMLStore.ctxType;
    rows NUMBER;
    xmldoc CLOB :=
    '<ROWSET>
    <ROW num="1">
    <EMPNO>7369</EMPNO>
    <SAL>1800</SAL>
    <HIREDATE>27-AUG-1996</HIREDATE>
    </ROW>
    <ROW>
    <EMPNO>2290</EMPNO>
    <SAL>2000</SAL>
    <HIREDATE>31-DEC-1992</HIREDATE>
    </ROW>
    </ROWSET>';
    BEGIN
    insCtx := DBMS_XMLStore.newContext('scott.emp'); -- get saved context
    DBMS_XMLStore.clearUpdateColumnList(insCtx); -- clear the update settings
    -- set the columns to be updated as a list of values
    DBMS_XMLStore.setUpdateColumn(insCtx,'EMPNO');
    DBMS_XMLStore.setUpdateColumn(insCtx,'SAL');
    DBMS_XMLStore.setUpdatecolumn(insCtx,'HIREDATE');
    -- Now insert the doc.
    -- This will only insert into EMPNO, SAL and HIREDATE columns
    rows := DBMS_XMLStore.insertXML(insCtx, xmlDoc);
    -- Close the context
    DBMS_XMLStore.closeContext(insCtx);
    END;
    /

    You ask where am getting the XML doc. Well, am not
    getting the doc itself.I either don't understand or I disagree. In your sample code, you're certainly creating an XML document-- your local variable "xmldoc" is an XML document.
    DBMS_XMLSTORE package needs
    to know the canonical format and that's what I
    hardcoded. Again, I either don't understand or I disagree... DBMS_XMLStore more or less assumes the format of the XML document itself-- there's a ROWSET tag, a ROW tag, and a then whatever column tags you'd like. You can override what tag identifies a row, but the rest is pretty much assumed. Your calls to setUpdateColumn identifies what subset of column tags in the XML document you're interested in.
    Later in code I use
    DBMS_XMLStore.setUpdateColumn to specify which
    columns are to be inserted.Agreed.
    xmldoc CLOB :=
    '<ROWSET>
    <ROW num="1">
    <KEY_OLD> Smoker </KEY_OLD>
    <KEY_NEW> 3 </KEY_NEW>
    <TRANSFORM> Specified </TRANSFORM>
    <KEY_OLD> Smoker </KEY_OLD>
    <VALUEOLD> -1 </VALUEOLD>
    EW> -1 </VALUENEW>
         <DESCRIPTION> NA </DESCRIPTION>
    </ROW>
    ROWSET>';This is your XML document. You almost certainly want to be reading this from the file system and/or have it passed in from another procedure. If you hard-code the XML document, you're limited to a 32k string literal, which is almost certainly causing the error you were reporting initially.
    As am writing this I'm realizing that I'm doing this
    wrong, because I do need to read the XML file from
    the filesystem (but insert the columns
    selectively)...What I need to come up with is a proc
    that would grab the XML file and do inserts into a
    relational table. The XML file will change in the
    future and that means that all my 'canonical format'
    code will be broken. How do I deal with anticipated
    change? Do I need to define/create an XML schema in
    10g if am just inserting into one relat. table from
    one XML file?What does "The XML file will change in the future" mean? Are you saying that the structure of the XML document will change? Or that the data in the XML document would change? Your code should only need to change if the structure of the document changes, which should be exceptionally uncommon and would only be an issue if you're adding another column that you want to work with, which would necessitate code changes.
    I found an article where the issue of changing XML
    file is dealt by using a XSL file (that's where I'd
    define the 'canonical format'), but am having a
    problem with creating one, because the source XML is
    screwed up in terms of the format:
    it's not <x> blah </x>
    <x2> blah </x2>
    x2="blah" x3="blah> ...etc
    Can you point me in the right direction, please?You can certainly use something like the DBMS_XSLProcessor package to transform whatever XML document you have into an XML document in an appropriate format for the XMLStore package and pass that transformed XML document into something like your sample procedure rather than defining the xmldoc local variable with a hard-coded document. Of course, you'd need to write appropriate XSL code to do the actual transform.
    Justin

Maybe you are looking for

  • Drag and drop a image from html page into flex

    how can i drag a image form the html page and drop it into the flex application.

  • IPhoto 6 Speed Issue

    With iPhoto 5, if I used the down arrow on the keyboard to advance one picture at a time, iPhoto used to cache the next picture in memory so that it would pop up instantaneously. iPhoto 6 seems to have lost this ability. Every time I advance to the n

  • Extract CRM Master Data - Ad Hoc Query

    Hi, Does anyone know of a tool in CRM like Ad Hoc Query in HR? Basically I'm looking for an end user tool that allows the user to pull of Master Data. Effectively like a report but they can pick and choose the data they want it to search on. Any help

  • How to migrate forms 6i designed in windows to forms6i for linux

    Hi, Guys I'm trying to migrate a forms designed in windows to linux, but when I pass the fmb and compile with f60gen in linux the fields in the form are little and no see the information in other words the form is no same. How do I do for look the fo

  • Windows users heads-up: If you installed plug-ins under \Program Files\Adobe\Adobe Photoshop Lightro

    The SDK documentation has always recommended that you install plug-ins in the App Data folder: In Windows XP, "C:\Documents and Users\username\Application Data\Adobe\Lightroom\Modules" In Windows Vista, "C:\Users\username\AppData\Roaming\Adobe\Lightr