Recursive information, how to create a recursive query with a table?

Hello

I have some data from a table and is stored in the following way:


Building blocks
4040 x 1, x 3, x 4
4040 c3, c7, c9
4040 j5, j7,
4040 s8
4041 f4
4041 x 1, x 2, x 3

I need to record in another table component and all of its units in one line, like this

Component Total_units
4040 x 1, x 3, x 4, c3, c7, c9j5, j7, s8
4041 f4, x 1, x 2, x 3


I tried with subqueries, combination, and I can't get in a data record.

I really appreciate your help!

Nicolas

The solution with xmlagg
Note: remove the end (en) this record 4040 j5, j7, manually
You can use the TRIM function to remove this as a GARNISH (end ',' units)

WITH dat as (select 4040 Component, 'x1,x3,x4'   Units from dual
union all    select 4040, 'c3,c7,c9' from dual
union all    select 4040, 'j5,j7' from dual
union all    select 4040, 's8' from dual
union all    select 4041, 'f4' from dual
union all    select 4041, 'x1,x2,x3' from dual
)
SELECT      Component
        ,TRIM (leading ',' from XMLAGG(XMLELEMENT(a,','||units).extract('//text()'))) col_name
 FROM      dat
GROUP BY component
/

 COMPONENT COL_NAME
---------- -------------------------------------
      4040 x1,x3,x4,c3,c7,c9,j5,j7,s8
      4041 f4,x1,x2,x3

SS

Tags: Database

Similar Questions

  • recursive query with two tables

    Hello

    Im having problems of recursive query construction and add to select the list to see the result in hierarchical mode, so I want to your advice.

    I have two tables:
    TABLE: t1 
    c_id       parent_id      c_level
    1              -                 1
    2              1                 2
    3              1                 2
    4              -                 1
    5              4                 2
    6              5                 3
    
    TABLE: t2 
    c_id         c_name
    1               name1
    2               name2
    3               name3
    4               name4
    5               name5
    6               name6
    And I want to see the result like this:

    -Name1
    -name2
    -Name3
    -Name4
    -Name5
    -name6

    Could you please help me with this?
    Or maybe can you provide good links where I can find solution how to SELECT LIST looks like the hierarchical tree?

    Here is my test scenario:

    CREATE TABLE t1(
      c_id      NUMBER,
      parent_id NUMBER,
      c_level   NUMBER);
    
    CREATE TABLE t2(
      c_id   NUMBER,
      c_name VARCHAR2(10));
    
    INSERT INTO t1 VALUEs(1,NULL,1);
    INSERT INTO t1 VALUEs(2,1,   2);
    INSERT INTO t1 VALUEs(3,1,   2);
    INSERT INTO t1 VALUEs(4,NULL,1);
    INSERT INTO t1 VALUEs(5,4,   2);
    INSERT INTO t1 VALUEs(6,5,   3);
    
    INSERT INTO t2 VALUEs(1,'name1');
    INSERT INTO t2 VALUEs(2,'name2');
    INSERT INTO t2 VALUEs(3,'name3');
    INSERT INTO t2 VALUEs(4,'name4');
    INSERT INTO t2 VALUEs(5,'name5');
    INSERT INTO t2 VALUEs(6,'name6');
    
    SELECT LPAD('-',2 * a.c_level,'-') || b.c_name the_tree
      FROM t1 a,
           t2 b
     WHERE b.c_id = a.c_id
    CONNECT BY a.parent_id = PRIOR a.c_id
     START WITH a.parent_id IS NULL;
    

    and the result:

    THE_TREE
    ----------
    --name1
    ----name2
    ----name3
    --name4
    ----name5
    ------name6
    

    I took the example you gave then perhaps your largest data set has the flaw?

    Published by: SunDogCa on August 13, 2010 14:19

  • How to create a recovery disc with all vista updates?

    original title: how to create a recovery disc with all vista updates without starting from scratch, so I can replace my hard drive?

    My hard drive seems to be dying.  I would replace the drive.  I reloaded vista from scratch with all the updates, but it took forever.  I would like to make a record of recovery with all updates.  IAM on vista Home premium.  32 bit

    If you want a good backup program that backups image, I recommend Acronis True Image 2010:http://www.acronis.com/homecomputing/products/trueimage/.  It offers a free trial, so you can test and if you want it's only about $30 for the original version.  A lot of people I know this program and use it instead of Vista even in versions of Vista that offers imagery as this program does a better job.  Of course you also need a place to put the backup (which will take a lot of space), so also consider.  The best choice would be a USB external hard drive at least as large as the readers you want to back up (not only the data on them, but the entire available disk space, so you miss when you add more information about the disks).

    You cannot use IMGBURN do - it can't do anything like that.  It must be the imagery of backup software.

    I hope this helps.

    Good luck!

    Lorien - MCSA/MCSE/network + / has + - if this post solves your problem, please click the 'Mark as answer' or 'Useful' button at the top of this message. Marking a post as answer, or relatively useful, you help others find the answer more quickly.

  • I need to update the screenshots for a new version of an app existing Itune application to download a new version. Since I did not create the original version, can you guide me how to create a new version with the new version number?

    I need to update the screenshots for a new version of an existing iTunes Connect App asks me to download a new version. Since I did not create the original version, can you guide me how to create a new version with the new version number?

    You must call the assistance of the company and ask them to help you with this. You can find contact information by logging on http://digitalpublishing.acrobat.com/ and looking at the Middle at the bottom of the page.

    Neil

  • How to create the new domain with lookup?

    How to create the new domain with list of choices like terrain dDocType system?

    Administration/Admin Applets tab / SCCM / information fields.
    Add field or edit a custom field if you have one.
    The name field (the name will be prefaced with the lowercase letter x behind the scenes, if ever, you write the code to call it if you name this Fruit it will xFruit for code)
    Define your values for the field, but the important thing for a menu drop-down list or list of selection will be to list the Option activate the checkbox.
    Then, you perform one of the 3 main things to put data in the list.
    1. manually fill in a list of options
    2. use a DB or DB table view to view Configuration Manager
    3. create a complex tree (read the documentation on which I him have not used)

    If this does not answer your questions, click the help button in the applet.

  • How to create a photo album with ms office?

    How to create a photo album with ms office? I tried to use picasa, but I don't know how to make an album. I also want to add a text below.

    Click on the Forums link at the top of the page and go on the forums of office to ask. But, if you can not understand Picasa, you'll probably some luck using nothing else. Consider going on the forums of Picasa and get help.

  • How to create a new project with other page with the new version of Muse layouts?

    Hello
    If someone would continue to operate as before with the inadmissible Muse version... is - this posible to have both versions installed? or how to create a new project with other page with the new version of Muse layouts?
    Or how to download third party) 3 different configurations (desktop/tablet/mobile) under the same url with a clean result, like up yet with the Muse does not?

    Thanks for any help,

    Patrick

    Use the new version! What you want to achieve, will work! Go to the 'Page' menu and choose 'Add another Layout' and the missed buttons are in plan view.

  • How to create a menu manual, WITH dropdowns

    How to create a menu manual, WITH dropdowns

    You can use the "Composition" widget with these settings:

    Note: Use triggers to place your text. You can use each box to add all your links on the page in question.

  • How to create a tabular report with alphabetical link at the top

    Hello

    I have a db of the users table and have created a report based on this table, but I want that each letter of the alphabet at the top of the report so that users can click on the letter and see all the records where the username field begins with that letter.

    How can I achieve this?

    Thank you

    Hello user11243298 (please tell us your name).

    Your report query might look like this (assuming that the page number is 1):

    Select some_column1, some_column2
    of your_user_table
    where username as: P1_INITIAL | '%'

    For the letters at the top of the report, here are some options:

    -If you want that all the letters to appear or not lines, you can create a series of buttons or links, one for each letter and specify the target URL make return to the report page, defining the P1_INITIAL element to each letter.

    -If you want only the letters which were stored, is to create a dynamic LOV based on a query like this:

    Select distinct superior (substr (username, 1, 1)) d, high separate v (substr (username, 1, 1))
    of your_user_table
    order from the top (substr (username, 1, 1))

    Can use it for a list of selection with submit, again targeting the report page and the P1_INITIAL parameter to the selected value.

    Hope this helps (if this is the case, please reward it),.
    John

  • How to create a view in the DB table for some servers

    Hello

    We need create a country table which will contain data for countries.

    I want to create it in such a way that it will be common for all servers - but as a point of view. not the real table, only the data and views do not change.

    How can I do?

    Thanks in advance

    Are you sure you want to say 'tablespace '? A tablespace is a collection of data files. It has nothing to do with the privileges of the object, object namespaces, etc. I'm guessing that you mean that you have two schemas, OBITUARIESCS and ADVERTISEMENTCS. A schema is a collection of objects of database belonged to a particular user. A single table can exist in spaces of multiple tables (assuming it is partitioned). Different schemas can have an infinite number of tables with the same name in the same table. The database schema is the namespace for objects such as tables.

    Assuming that you have two schemas in your database, you can create a table of COUNTRIES in the OBITUARIESCS schema. You can then grant SELECT access on the table to another user, ADVERTISEMENTCS, i.e.

    GRANT SELECT ON country TO advertisementcs
    

    You can then ask questions (but not change) the COUNTRY code of the property of ADVERTISEMENTCS table

    SELECT *
      FROM advertisementcs.country
    

    If you want to be able to remove the prefix in the schema, you can create a synonym. In the ADVERTISEMENTCS schema

    CREATE SYNONYM country
      FOR advertisementcs.country
    

    and then when the code of the property of ADVERTISEMENTCS wants to query the countries table, it can just

    SELECT *
      FROM country
    

    Justin

  • I have a column with two values, separated by a space, in each line. How to create 2 new columns with the first value in a column, and the second value in another column?

    I have a column with two values, separated by a space, in each line. How do I create 2 new columns with the first value in one column and the second value in another column?

    Add two new columns after than the original with space separated values column.

    Select cell B1 and type (or copy and paste it here) the formula:

    = IF (Len (a1) > 0, LEFT (A1, FIND ("", A1) −1), ' ')

    shortcut for this is:

    B1 = if (Len (a1) > 0, LEFT (A1, FIND ("", A1) −1), ' ')

    C1 = if (Len (a1) > 0, Member SUBSTITUTE (A1, B1 & "", ""), "")

    or

    the formula of the C1 could also be:

    = IF (Len (a1) > 0, RIGHT (A1, LEN (A1) −FIND ("", A1)), "")

    Select cells B1 and C1, copy

    Select cells B1 at the end of the C column, paste

  • Satellite P840: How to create the secure boot with UEFI Bios recovery disk

    Hello

    I have laptop P840 that came pre-installed with Windows 8, which I've upgraded to Windows 8 Pro.
    I then updated to Windows Pro 8.1 by Windows store. Please notify:

    1. how to create a DVD repair or start for windows 8.1 pro with UEFI Bios and boot secured.

    2. I created a USB recovery using the control panel in Windows Pro 8.1. It starts OK. It will be the same as that I've created using the Toshiba Media recovery creator or will it drivers Windows Pro 8.1?

    3. check partitions with disk management, then 3 (450MO, 350 MB and GB 10.90) recovery partitions, 1 EFI system partition and 2 primary (C: programs) and D: for data. I created the recovery DVD and USB 2 disks. Can I remove the 3 recovery partitions?

    Your help will be very appreciated.

    Best regards

    Romero

    I found your previous thread on this topic:
    http://forums.computers.Toshiba-Europe.com/forums/thread.jspa?threadID=74272

    > 1. How to create a DVD repair or start for windows 8.1 pro with UEFI Bios and boot secured.
    To be able to boot from sources other than the drive HARD internal, the boot mode must be set to the CSM and secure boot must be disabled!

    > 2. I created a USB recovery using the control panel in Windows Pro 8.1. It starts OK. It will be the same as that I've created using the Toshiba Media recovery creator or will it drivers Windows Pro 8.1?

    Your laptop has been preloaded with Win 8. Right? For example, the USB flash stick memory you just use the Toshiba Recovery media creator contains the Image of Toshiba with Windows 8. Don t mix this Toshiba image with the image that can be created using Microsoft's own backup and restore function. Both are different pictures!

    > 3. Check it with disk management, then 3 (450MO, 350 MB and GB 10.90) recovery partitions, 1 EFI system partition and 2 partitions primary (C: programs) and D: for data. I created the recovery DVD and USB 2 disks. Can I remove the 3 recovery partitions?

    The last partition contains the files on HARD drive recovery. Usually this partition will be created again when you use the Toshiba Recovery disk to put the laptop back to factory settings. So in the case where you n t need this files or the partition, you can delete

  • How to create a status column in the table

    Hello everyone

    I am trying to create a column of the table status in frontview Panel. I enclose a picture with her to say clearly what I say.plz tell me how to create the active status column in the table.

    I want to show green for safety stock and red for safety stock below.


  • How to create a horizontal Gallery with buttons?

    I can't understand how to create a way to show my photos as a horizontal Gallery with buttons to scroll (photos at left), as Elizabeth Gadd photography . Can anyone help?

    Have you looked at the standard slideshow and Lightbox widget or sought another widget "image Carousel"? It's really basic things.

    Mylenium

  • How to create the energy bar with flash pro?

    Hello

    How to create an energy bar as what you see in flash facebook games, which increases with time "as every minute add 1 energy point' and reduce playing a role or a battle or just do an action?

    You can simply use a rectangular moviweclip/sprite and use Actionscript to control the width (or height), where the energy is proportional to the value of the width (or height).  You can also pair with a textfield that allows you to display the actual value of energy as it changes.

Maybe you are looking for

  • After I updated to Firefox Win8.1 begins to crash.

    I had been using Firefox 26 on Win8 and it worked very well. I've updated to Win8.1 and now Firefox crashes all the time. The entire system freezes and help only turns off the computer.

  • IS

    Hello I am from the Netherlands, and I really want to buy the iPhone SE. One of my friends goes to Boston and New York soon and he offered to pick one for me. I have a question about free iPhone simlock SE. Is the iPhone that you buy without the alwa

  • killer app for pre?

    I just got my Palm Pre (after my beloved Palm Treo collapsed )... when I read the reviews and saw many people complain about the battery life, I wasn't worried because I do not use my phone all day.  However, OMG, this Palm Pre sucks the life out of

  • How can you tirn on blue tooth on a computer vista laptop

    My back at the top of the tower is supposed to be blue too compatiable. Unfortunately, this wont work because I can't turn it on in his laptop in blue tooth. She has an Ispirion dell.

  • If I format my drive and install linux, how do I install and activate my windows?

    * Original title: reinstalling Windows 7 Hello I bought a laptop recently, with a pre installed, activated windows 7. I'll be using linux for some time and goes back to Windows. If I format my drive and install linux, how do I install and activate my