Combining XML into Array

BANNER
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
PL/SQL Release 11.2.0.1.0 - Production
CORE    11.2.0.1.0      Production
TNS for Linux: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - ProductionI'm having trouble combining two pieces of sql using xml. I'm building an array of "items" using a select statement that works just fine. (contained_by is the parent of all the children in the array with the same contained by value)
SELECT XMLELEMENT("itemArray", XMLAGG(extract(xml_data,'/item')))    
FROM description_test
WHERE contained_by = 181315;
<itemArray>
   <item>...</item>
   <item>...</item>
   <item>...</item>
</itemArray>Now, when I try to "attach" the parent, I can't seem to get it to work.
SELECT p.naId, XMLCONCAT(extract(p.xml_data,'/fileUnit'),
           XMLAGG(XMLELEMENT("itemArray", extract(c.xml_data,'/item'))))
FROM description_test p --parent,
description_test c --child
WHERE c.contained_by = p.naid;
ORA-00937: not a single-group group function
00937. 00000 -  "not a single-group group function"
SELECT p.naId, XMLCONCAT(extract(p.xml_data,'/fileUnit'),
       XMLAGG(XMLELEMENT("itemArray", extract(c.xml_data,'/item'))))
FROM description_test p, --parent,
description_test c --child
WHERE p.desc_type = 'FU'
AND c.contained_by = p.naid
and rownum < 5
group by p.naid;
ORA-00979: not a GROUP BY expression
00979. 00000 -  "not a GROUP BY expression"what I'm expecting is the following to come back :
<fileUnit>
   <some_data/>
   <more_data/>
   <itemArray>
      <item>...</item>
      <item>...</item>
      <item>...</item>
   </itemArray>
</fileUnit>Not sure why this is not working. If I do the same thing without trying to build the xml array I get the following:
SELECT p.naId, count(c.naid) AS CHILD_COUNT
FROM description_test p,
description_test c
WHERE c.contained_by=p.naid
group by p.naid;
NAID  CHILD_COUNT
135801     25
174634     1
137211     15
136529     30
143455     36
145696     42Help is greatly appreciated. Thanks!!!

Hi,
As always, some sample data would help to understand the problem.
From what you've posted so far, I assume something like this :
create table description_test (
  naid number
, contained_by number
, xml_data xmltype
insert into description_test values (1, null, xmltype('<fileUnit><some_data/><more_data/></fileUnit>'));
insert into description_test values (2, null, xmltype('<fileUnit><some_data/><more_data/></fileUnit>'));
insert into description_test values (3, 1, xmltype('<item>item 1.1</item>'));
insert into description_test values (4, 1, xmltype('<item>item 1.2</item>'));
insert into description_test values (5, 1, xmltype('<item>item 1.3</item>'));
insert into description_test values (6, 2, xmltype('<item>item 2.1</item>'));
insert into description_test values (7, 2, xmltype('<item>item 2.2</item>'));What you're trying to do implies grouping on an XMLType column, which is not possible since the XMLType object doesn't have any MAP or ORDER method.
The solution is to use a subquery, like below.
It also seems that you want insert, not concat :
SQL> select p.naid
  2       , insertchildxml(
  3           p.xml_data
  4         , '/fileUnit'
  5         , 'itemArray'
  6         , (
  7             select xmlelement("itemArray", xmlagg(c.xml_data))
  8             from description_test c
  9             where c.contained_by = p.naid
10           )
11         ) as fileunit
12  from description_test p
13  where p.contained_by is null
14  ;
NAID FILEUNIT
   1 <fileUnit>
       <some_data/>
       <more_data/>
       <itemArray>
         <item>item 1.1</item>
         <item>item 1.2</item>
         <item>item 1.3</item>
       </itemArray>
     </fileUnit>
   2 <fileUnit>
       <some_data/>
       <more_data/>
       <itemArray>
         <item>item 2.1</item>
         <item>item 2.2</item>
       </itemArray>
     </fileUnit>

Similar Messages

  • XML newbie question - xml into arrays

    I am pretty new xml and I am working with a file that has
    text
    associated with images in the file and I would like to move
    the text
    into a xml document.
    I heard that a good way to deal with xml is to load it into
    an array. I
    have my text set up in arrays already, so my whole file
    aready works in
    that way. So all I have to do is load my xml document into my
    arrays. I
    have the xml document loading fine, but I don't know how to
    get the info
    into my arrays.
    My xml document looks like this:
    <?xml version="1.0" encoding="utf-8" standalone="yes"?>
    <index_content>
    <image no="1">
    <imgLink>"pages/collection.html"</imgLink>
    <title>"Title 01"</title>
    <text>"Text bla bla, bla 01, Text bla bla, bla
    01"</text>
    <corner>"unisex"</corner>
    </image>
    <image no="2">
    <imgLink>"pages/collection.html"</imgLink>
    <title>"Title 02"</title>
    <text>"Text bla bla, bla 02, Text bla bla, bla
    02"</text>
    <corner>"men’s & women’s"</corner>
    </image>
    <image no="3">
    <imgLink>"pages/collection.html"</imgLink>
    <title>"Title 03"</title>
    <text>"Text bla bla, bla 03, Text bla bla, bla
    03"</text>
    <corner>"men’s & women’s"</corner>
    </image>
    <image no="4">
    <imgLink>"pages/collection.html"</imgLink>
    <title>"Title 04"</title>
    <text>"Text bla bla, bla 04, Text bla bla, bla
    04"</text>
    <corner>"men’s & women’s"</corner>
    </image>
    </index_content>
    My arrays in Flash are:
    var imgLinkURLs:Array = [];
    var imgTitles:Array = [];
    var imgTexts:Array = [];
    var imgCornerLabel:Array = [];
    So I think i need for loops pushing for example imgLink from
    image no1
    into imgLinkURLs array, then push imgLink from image no2, and
    so forth.
    Then do the same for imgTitle and the other arrays...
    How would I do this the right way?

    you can do it in just one loop, going through all the image
    tags in index_content and for each tag fill the values of all four
    arrays
    for (i...) {
    get the appropriate child of index_content
    first_array[ i ] = value of first tag
    second_array[ i ] = value of second tag
    no need for multiple loops.
    flash has functionality for xml files, but it helps to write
    a little wrapper around it, to simplify programming, especially if
    you work with xml a lot.. I wrote my for work, so I can't show it
    to you, but it's not very complicated to do

  • Parsing XML into Array problem

    my previous problem had turned slightly into a different
    issue;
    basically now when i trace the variables i'm getting
    undefined. Any help is great appreciated. Thanks!

    >>description
    = award.secondChild.nodeValue
    there is no such thing as secondChild.
    >>image = new Array(images.length);
    Where is image defined initially? You can't just use an index
    like that if
    image isn't already an array.
    I would suggest changing the structure a little. An array of
    award objects
    might work well.
    var allAwards = new Array();
    var award = new Object();
    award.caption = "my caption";
    award.images = new Array();
    allAwards.push(award);
    Then you can do like:
    trace(allAwards[0].caption);
    Dave -
    www.offroadfire.com
    Head Developer
    http://www.blurredistinction.com
    Adobe Community Expert
    http://www.adobe.com/communities/experts/

  • XML going into Arrays is killing my movie

    I'm loading a large xml file into flash.
    I think the amount of data going into Arrays is killing my
    move. So what are the work arounds?

    If the built-in XML parser is getting bogged because there is
    too much to
    handle, you ought to try loading smaller chunks of data.
    "mcshaw" <[email protected]> wrote in
    message
    news:e7ueac$md0$[email protected]..
    > I'm loading a large xml file into flash.
    > I think the amount of data going into Arrays is killing
    my move. So what
    are the work arounds?

  • Combining two StringBuffer array elements into a single array element

    I just need to know how to combine two stringBuffer array elements into one
    StringBuffer ciphertext [] = new StringBuffer[2];
              StringBuffer s0 = new StringBuffer("11011111111110001001101110110101");
              StringBuffer s1 = new StringBuffer("00010011001101000101011101111001");
              ciphertext[0] = s0;
              ciphertext[1] = s1;
              ciphertext[2] = ciphertext[0].append(ciphertext[1]);I get an array index out of bounds exception:2
    Thanks

    StringBuffer ciphertext [] = new StringBuffer[3];  // legal index values are: 0,1,2

  • Transforming XML into complex type in ADF/Java

    Hi all,
    Maybe a simple question for you all - maybe too simple for some of you - but not for me as a Java newbie. So I'd appreciate any help.
    I have used a WebService Proxy and created a new Pojo in order to create a Data Control. The WS proxy works quite good and I can get this XML response as expected.
    <ns0:kunden xmlns:ns0="http://www.oracle.com/hbv">
    <ns0:kunde>
    <ns0:Kundennummer>0000000047</ns0:Kundennummer>
    <ns0:Name>Laue</ns0:Name>
    <ns0:Vorname>Ingo</ns0:Vorname>
    <ns0:Straße>Kühnehöfe</ns0:Straße>
    <ns0:Hausnr/>
    <ns0:PLZ>22761</ns0:PLZ>
    <ns0:Ort>Hamburg</ns0:Ort>
    <ns0:Telefon>040/89091-456</ns0:Telefon>
    </ns0:kunde>
    <ns0:kunde>
    <ns0:Kundennummer>0000000048</ns0:Kundennummer>
    <ns0:Name>Brüning</ns0:Name>
    <ns0:Vorname>Arne</ns0:Vorname>
    <ns0:Straße>Kühnehöfe</ns0:Straße>
    <ns0:Hausnr/>
    <ns0:PLZ>22761</ns0:PLZ>
    <ns0:Ort>Hamburg</ns0:Ort>
    <ns0:Telefon>040/89091-220</ns0:Telefon>
    </ns0:kunde>
    </ns0:kunden>
    Now I want to transfer the XML into a complex type in Java, for instance
    ArrayList<MyKunde> retKundenliste = new ArrayList<MyKunde>();
    The type MyKunde is defined with all needed attributes and the corresponding getter/setter methods. My object getting the XML response from the WS is kundenliste of type javax.xml.soap.SOAPElement (defined by the WS proxy) . What method do I have to use to get all elements from the XML structure transformed into an array of MyKunde?
    I can imagine that this task is a standard but as I said I'm new in Java programming.
    Many thanks for your help
    Detlef

    I'm not sure but the Wizard should have created accessors for the char_list Adobe in the generated AbcXyzObj.java class. Check this class for the attributes and their getters and setters.
    Timo

  • Combine images into one image

    I have 13 small images 100x100, and I would like to combine them into one 1300x1300 image.  I have all the latest vision assistant and IMAQ software.  I can't figure out an easy way to do this using Labview?  Any help would be greatly appreciated.
    Kevin Baker

    I am not too familiar with IMAQ but have done LV image processing where you can use an array to represent the data (I think IMAQ uses some border pixels in their array to accomidate for image processing near image edges).  You can initialize a 700x700 array (use a numeric type which agrees with your image bit depth, then for each image use the replace array subset with the column/ row corresponding to the x,y location of the origin (upper left  corner) of each image to replace, the length of each subset is equal to the width and height (100 in this case) of the inserting image.  So for image 1 the replace subset would be:
    column = 300, length = 100, row =0, length 100.
    Repete this for all 13 images.  As for the IMAQ conversion I dont know the answer since I dont have a copy of IMAQ.
    Paul
    Paul Falkenstein
    Coleman Technologies Inc.
    CLA, CPI, AIA-Vision
    Labview 4.0- 2013, RT, Vision, FPGA

  • How to convert from XML to Array ?

    how to convert from XML to Array ?
    thanks in advance

    this is a segment of the xml object:
    var myXML:XML =
    <data>
    <task>
    <taskID>2</taskID>
    <startDate>2/15/2007</startDate>
    </task>
    </data>
    i want to conver myXML into ArrayCollection: like this:
    private var expenses:Array = [
    {taskID:"1", startDate:"2/15/2007"},
    {taskID:"2", startDate:"4/15/2007"}
    how i can do it ? and tell me how to retrieve the data from
    the collection
    thanks

  • Changing flat XML into nested

    I'm working on a tree navigation that needs to have some data provided in a nested xml format
    <node label="California">
         <node label="location 1" />
         <node label="location 2">
              <node label="option 1" />
              <node label="option 2" />
         </node>
    </node>
    But the data that I'm getting (and probably can't change) is coming out flat:
    <item>
         <id>12</id>
         <label>California</label>
    </item>
    <item>
         <id>15</id>
         <label>location 1</label>
         <parent>12</parent>
    </item>
    <item>
         <id>17</id>
         <label>location 2</label>
         <parent>12</parent>
    </item>
    <item>
         <id>33</id>
         <label>option 1</label>
         <parent>17</parent>
    </item>
    <item>
         <id>70</id>
         <label>loption 2</label>
         <parent>17</parent>
    </item>
    Any suggestions on how to change that data from what I'm supplied to what I need? Is it just a brute force looping through the xml nodes a bunch of times? Or is there a clever way that I'm not seeing?

    If you are sure about data integrity, especially ids relationships, the following is one of the ways to reposition nodes without changing general node structure. Following this logic you can restructure XML altogether.
    With that said, I am not sure XML restructuring is the best way to go anyway. I feel a much better solution would be to parse XML into a more native to AS3 structure like Array, Object or Vector. I would rather create a specialized data provider class.
    Example uses the following XML:
    <items>
        <item>
            <id>1</id>
            <label>California</label>
        </item>
        <item>
            <id>2</id>
            <label>California location 1</label>
            <parent>1</parent>
        </item>
        <item>
            <id>3</id>
            <label>California location 1 option 1</label>
            <parent>2</parent>
        </item>
        <item>
            <id>4</id>
            <label>California location 1 option 2</label>
            <parent>2</parent>
            </item>
        <item>
            <id>5</id>
            <label>California location 1 option 3</label>
            <parent>2</parent>
        </item>
        <item>
            <id>6</id>
            <label>California location 2</label>
            <parent>1</parent>
        </item>
        <item>
            <id>7</id>
            <label>California location 2 option 1</label>
            <parent>6</parent>
        </item>
        <item>
            <id>8</id>
            <label>California location 2 option 2</label>
            <parent>6</parent>
        </item>
        <item>
            <id>9</id>
            <label>New York</label>
        </item>
        <item>
            <id>10</id>
            <label>New York location 1</label>
            <parent>9</parent>
        </item>
        <item>
            <id>11</id>
            <label>New York location 1 option 1</label>
            <parent>10</parent>
        </item>
        <item>
            <id>12</id>
            <label>New York location 1 option 1</label>
            <parent>10</parent>
        </item>
    </items>
    Code that parses this xml is (given the value of the xml above is assigned to var xml:XML
    var parent:XMLList;
    for each (var node:XML in xml.item)
        if (node.parent.toString() != "")
            parent = xml.item.(id == node.parent.toString());
            if (parent.parent.toString() == "")
                parent.@["type"] = "top";
            node.@["type"] = "child";
            parent.appendChild(node);
    xml = new XML(xml.toString());
    while (xml.item.(@type == "child").length() > 0)
        delete xml.item.(@type == "child")[0];
    trace(xml);
    Output is:
    <items>
        <item type="top">
            <id>1</id>
            <label>California</label>
            <item type="child">
                <id>2</id>
                <label>California location 1</label>
                <parent>1</parent>
                <item type="child">
                    <id>3</id>
                    <label>California location 1 option 1</label>
                    <parent>2</parent>
                </item>
                <item type="child">
                    <id>4</id>
                    <label>California location 1 option 2</label>
                    <parent>2</parent>
                </item>
                <item type="child">
                    <id>5</id>
                    <label>California location 1 option 3</label>
                    <parent>2</parent>
                </item>
            </item>
            <item type="child">
                <id>6</id>
                <label>California location 2</label>
                <parent>1</parent>
                <item type="child">
                    <id>7</id>
                    <label>California location 2 option 1</label>
                    <parent>6</parent>
                </item>
                <item type="child">
                    <id>8</id>
                    <label>California location 2 option 2</label>
                    <parent>6</parent>
                </item>
            </item>
        </item>
        <item type="top">
            <id>9</id>
            <label>New York</label>
            <item type="child">
                <id>10</id>
                <label>New York location 1</label>
                <parent>9</parent>
                <item type="child">
                    <id>11</id>
                    <label>New York location 1 option 1</label>
                    <parent>10</parent>
                </item>
                <item type="child">
                    <id>12</id>
                    <label>New York location 1 option 1</label>
                    <parent>10</parent>
                </item>
            </item>
        </item>
    </items>

  • I have 3 different itunes accounts and would like to combine them into just one for all my devices, a macbook pro, an iphone 4S, an older IPOD, and a ver sion one Ipad. how can i do this on all devices ?

    i have 3 different itunes accounts and would like to combine them into just one for all my devices, a macbook pro, an iphone 4S, an older IPOD, and a ver sion one Ipad. how can i do this on all devices ?

    i had one for a long time, then when i got the ipad i didn't realize they would all still work under one so i set up the second one on that
    then when i got the new iphone i put in the info for the first and main one from my mac pro and it would not work at all, and i knew it was right, then it asked me to create a new one or i couldnt finish the setup
    hence why i have 3 now
    hard to believe you cannot combine into one
    oh well, i will just make them all accessible for all 3
    thanks

  • Trying to drag pdf files i have and combine them into one pdf file in the account i just purchased with Adobe. when i drag a pdf file over Adobe doesn't accept it. says it can not convert this type of file. but it is an Adobe file. Do I need to change it?

    Trying to drag pdf files i have and combine them into one pdf file in the account i just purchased with Adobe. when i drag a pdf file over Adobe doesn't accept it. says it can not convert this type of file. but it is an Adobe file. Do I need to change it in some other form befor dragging it?

    Hello djensen1x,
    Could you please let me know what version of Acrobat are you using.
    Also, tell me your workflow of combining those PDF files?
    Please share the screenshot of the error message that you get.
    Hope to get your response.
    Regards,
    Anubha

  • I have several pics of my new grandson throughout the year.  How do I combine them into one event

    I have several pics of my new grandson throughout the year.  How do I combine them into one event

    You can drag and drop photos from one Event to another. Or you can flag them and use the Events: Add Flagged photos to Select Event.
    However, why not use an Album for the job?

  • I have two different itunes music files on my computer.  How do I combine them into one file?

    I have two different itunes music files on my computer.  How do I combine them into one file?

    I don't think so. The only other ID I have is a developer id, and I didn't get that until several months after I got the phone. In addition purchases I made from the App Store onthe phone would sync up with It unes on the Mac meaning it would be the same id.
    However I looked at the AppStore on my phone while it was connected to the Mac with iTunes open, and now the balance has changed to the same as the others.

  • I seem to have at least two, and maybe four, iCloud accounts, across my iPhone, my iPad and my MacBook Pro. Can I combine them into one iCloud account?

    I seem to have at least two, and maybe four, iCloud accounts, across my iPhone, my iPad and my MacBook Pro. Can I combine them into one iCloud account? I have been able to log into what appears to be three of the four iCloud accounts I have. Two of them seem to be remarkably similar, and one appears to be only for my MacBook.I think I know which one my iPhone is backing up to, as I successfully restored from a back-up last week. The fourth iCloud account I can't access via password or security questions. Any advice would be much appreciated.
    Thanks.
    Cheers,
    Aaron
    Melbourne, Australia

    You cannot merge accounts.

  • I have multiple documents how can I combine them into one document?

    I have multiple document files in Pages. How can I combine them into one document?

    Menu > View > Page Thumbnails > click on the thumbnails > Copy/Paste into thumbnails of other document
    Peter

Maybe you are looking for

  • SURLError 1005? What's That All About?

    Howdy folks, fairly new mac user here. Everything's been just dandy for the last month but tonight Safari took a few attempts to get going: giving me this error code of 1005. After I finally got it running it seems slower than normal and I'm having a

  • Assignment of taxcode to GL account

    hai guys, can anybody say, how we can assign the taxcode to GL account thanx vamshi

  • List of libraries/lists in SharePoint 2013

    I want to get list of all libraries along with sizes ( including permissions if possible) in top level site collection and also there is subsite under this , I need same information for the subsite. Is there any way we can get it through or some thir

  • Delete millions of rows and fragmentation

    Hi Gurus, i have deleted 20 lak rows from a table which has 30 lak rows, and i wanted to release the fragmented space , please tell me the procedure other than exp/imp or alter table move and also the recommended way to do this prod env... (coalesce

  • IC Booking - Same Account Issue

    Hi, My company is using the same account for both Inter company AR & AP. I tried configuring the BR for IC Booking but it did not work. I am using the seller wins scenario and posting the Debit to a generic Difference account and Credit to this same