Problem with derivation of tree-like structure by means of query

Hi.
My name is Viktor. I'm from Russia so sorry for my English:)
You know I have the following problem:
Input data: For example, I have the following table with hierarchy (where ParentID is ID of the parent element in the same table, also we dont know the amount of levels in hierarchy previously).
Input table:
ID --------------Name----------- ParentID
1 ----------------Russia------------- Null
2 ----------Centr. Fed.Circle------ 1
3 -----------South.Fed.Circle------ 1
4 -----------Moscow region ---------2
5 --------------Podolsk ----------------4
Tell please how to receive the broach of that table with hierarchy by means of hierarchical query (or group of queries) to the following table:
Result table:
Attribute1------ Attribute2------------ Attribute3------------ Attribute4
Russia--------------Russia ----------------Russia------------------Russia
Russia -------Centr. Fed.Circle -----Moscow region --------Podolsk
Russia -------South.Fed.Circle ------South.Fed.Circle -----South.Fed.Circle
That is I need that the input table with the hierarchy would expand in the corresponding amount of columns in the result table (it depends on the amount of level in the input table) and would in due order, that is where we havenot value for level (for example we havenot values for the element Russia (first row in column Attribute1 in the result table in the following columns: Attribute2, Attribute3, Attribute4) we must fill these columns by the value from previous level.
I think you understood my task. If necessary i can give eхplanation more. Thanks for help.
Best regards, Viktor
Edited by: user8017496 on 10.02.2009 10:39
Edited by: user8017496 on 10.02.2009 10:52

Hi,
Below is a dynamic solution for SQL*Plus.
If you want to do this in PL/SQL, this should show you how.
--     *****  Start of dynamic_pivot.sql  *****
-- Suppress SQL*Plus features that interfere with raw output
SET     FEEDBACK     OFF
SET     PAGESIZE     0
-- Preliminary query to write 2nd, 3rd, ... SELECT columns
SPOOL     p:\sql\cookbook\dynamic_pivot_subscript.sql
WITH     got_path     AS
     SELECT     LEVEL                     AS lvl
     FROM     input_table
     START WITH     parentid     IS NULL
     CONNECT BY     parentid     = PRIOR id
SELECT     ',     MAX (NVL (REGEXP_SUBSTR (path, ''[^/]+'', 1, '
     ||      TO_CHAR (LEVEL + 1)
     ||     '), name))     AS attribute'
     ||      TO_CHAR (LEVEL + 1)
FROM     dual
CONNECT BY     LEVEL     <     (
                    SELECT     MAX (lvl)
                    FROM     got_path
SPOOL     OFF
-- Restore SQL*Plus features suppressed earlier
SET     FEEDBACK     ON
SET     PAGESIZE     50
-- Main Query
WITH     got_path     AS
     SELECT     name
     ,     LEVEL                    AS lvl
     ,     SYS_CONNECT_BY_PATH (name, '/')     AS path
     FROM     input_table
     START WITH     parentid     IS NULL
     CONNECT BY     parentid     = PRIOR id
,     cntr     AS
     SELECT     LEVEL     AS n
     FROM     dual
     CONNECT BY     LEVEL     <=     (
                         SELECT     MAX (lvl)
                         FROM     got_path
SELECT     MAX (NVL (REGEXP_SUBSTR (path, '[^/]+', 1, 1), name))     AS attribute1
@p:\sql\cookbook\dynamic_pivot_subscript.sql
FROM     got_path
JOIN     cntr          ON n     <= lvl
GROUP BY     name;When I used the dynamic_pivot_subscript.sql on the folder p:\sql\cookbook, you can use any file on any folder available from your SQL*Plus client machine.
I'm not saying that there's anything wrong with 3 rows of output. I'm only saying that I don't understand why you want 3 rows, and why you want those 3 rows. If I understood the problem, then I could probably show you a solution.
I don't mind explaining things that you don't understand, but I don't want to waste time explaining things that you already do understand.
Fell free to ask specific questions.

Similar Messages

  • Access rights in case of a tree-like structure, with inheritance

    Hello,
    the project I've just started to work on should include an easy way (from the user's point of view) to grant/revoke access rights on a tree-like structure with inheritance.
    Basically we are working for several international companies who want to use our application to watch/manage some of their web projects - each project belongs to one company and consisting of several 'campaigns' in several countries (there can be several campaigns per country, but each campaign belongs to exactly one country).
    From our point of view this is a tree-like structure, with a 'root' node at the top level, 'companies' at the first level, 'countries' at the second level, 'campaigns' at the third level, and modules of our application (for example a module to display overall stats of the campaing, and so on) at the fourth level. There could be (and probably will be) some more levels, but that's not important at this point - it will always be a tree-like structure.
    The customer's reqirements are natural - the administrators should be able to grant/revoke access to 'subtrees' of this structure. For example the top managers should be able to see all the data related to their company, the local managers should be able to see all the data related to their company in the country they work in, etc. On the other hand the relular employees should not see some of the modules (with details about clients of the company).
    I wonder whether this can be solved using JAAS in an elegant and flexible manner - from the documents / whitepapers / tutorials I've seen till now it seems to me it seems to me not too suitable.
    All the data will be stored in relational database (Oracle, and in some cases PostgreSQL), and it would be nice to have the access rights stored in the same way (but it's not required). We have some ideas how to solve that using a single table containing paths in the tree, but at this point it's only an idea (not a single line of code written).
    We are sure somebody has already to solve such a problem - maybe using JAAS, maybe some other technology - and we don't want to reinvent a wheel. Do you have an idea how to solve this (using JAAS or something else)?

    Well, I forgot to explain what the 'inheritance' means ...
    We do not want to set the access right on each node of the tree - we prefer (as well as the users) to set/store only as much information as needed. We'd like the nodes to inherit the access rights from their parent nodes. For example we'd like granting access to particular project to mean granting access to all campaigns in all countries (related to the project), without the need to set and store these rights for each of the campaigns/countries.

  • Tree Like structures

    Dear All,
    I am working on some tree like structures querys.
    I am strucked up with one tricky concept.
    My Data is like as given below
    EMPNO MGR
    1
    2 1
    3 1
    4 2
    5 4
    Now my requirement states that I should display the date as given below
    1
    1 2
    1 2 4
    1 2 4 5
    Can anyone help me in designing a query.
    Appreciate your help on this.
    Thanks,
    Madhu K.

    If more levels are there then it should populate under different columns like col5 ..... That's fine, that's how it will work.
    There are only 4 levels above because that's just how the sample data is.
    1 2 3 4You'd think people could give suggestions that get you over the hard bit and then you do some work for anything that's not exactly right.
    SQL> ed
    Wrote file afiedt.buf
      1  WITH DATA AS(
      2   SELECT 1 a,0 b FROM dual UNION
      3   SELECT 2,1 FROM dual UNION
      4   SELECT 3,1 FROM dual UNION
      5   SELECT 4,2 FROM dual UNION
      6   SELECT 5,4 FROM dual UNION
      7   SELECT 6,5 FROM dual
      8  )
      9  SELECT SUBSTR(SYS_CONNECT_BY_PATH (a,' '),2) scbp
    10  FROM DATA
    11  CONNECT BY PRIOR a=b
    12  START WITH a=1
    13* ORDER BY 1
    SQL> /
    SCBP
    1
    1 2
    1 2 4
    1 2 4 5
    1 2 4 5 6
    1 3
    6 rows selected.
    SQL>

  • I am having problem with me Iphone4, looks like the mic of my phone is not working. no one can hear me if I make a call to them

    Can any one please help me I am having problem with me Iphone4, looks like the mic of my phone is not working. no one can hear me if I make a call to them. I have tried all restoring options but no use. please help me

    The mic on my iPhone4 has just quit also. Similar symptoms to yours in that people I'm talking to hear only static or my voice very faintly. The voice/memo recorder also only really records static.
    It happened suddenly and seemed to get better after a day or two but then went completely after another day.
    I'm returning it to Vodafone New Zealand shortly but will have to wait 5-10 days for a replacement. There are NO Apple accredited means to speed this procedure up in NZ.
    We don't even have a single physical Apple Store where you could walk in and talk to a Genius.

  • Problem with conversion of strings like THISStr - this_str capitalization

    Problem with conversion of strings like. THISStr -> this_str
    Can anybody pass on the reverse code. I have one, but its faulty.
    public static String convertFromPolycaps(String str) {
              Pattern pattern = Pattern.compile("\\p{Upper}+");
              Matcher matcher = pattern.matcher(str);
              StringBuffer result = new StringBuffer();
              // We do manual replacement so we can change case
              boolean notFirst = false;
              int grpP = 0, grpA = 0;
              String last = "";
              String now = "";
              while (matcher.find()) {
                   grpA = matcher.end();
                   if (notFirst) {
                        now = matcher.group().substring(0).toLowerCase();
                        if (grpA - grpP > 1) {
                             matcher.appendReplacement(result, now);
                             result =
                                  new StringBuffer(
                                       result.substring(0, (result.length() - 1))
                                            + "_"
                                            + result.substring(result.length() - 1));
                        } else {
                             matcher.appendReplacement(result, "_" + now);
                   } else {
                        matcher.appendReplacement(result, matcher.group().substring(0).toLowerCase());
                        notFirst = true;
                   grpP = matcher.end();
                   ////index++;
                   last = now;
              matcher.appendTail(result);
              System.err.println(str + " : " + result.toString());
              return result.toString();
         }succesfully converts :
    AccountNmnc : account_nmnc
    CustNameJ : cust_name_j
    Resume : resume
    BeneBrCode : bene_br_code
    ApprovedPerson : approved_person
    but fails for:
    GLCode : glcode
    VISHALErrCode : vishalerr_code
    GHASUNNAcNo : ghasunnac_no

    Can anybody pass on the reverse code. I have one, but
    its faulty.Post it, I'm sure we can fix it...

  • Why can't i downgrade to mavericks? i have got some problem with yosmite. i would like to downgrade to mavericks.please help me how to get it ? thanks

    why can't i downgrade to mavericks? i have got some problem with yosmite. i would like to downgrade to mavericks.please help me how to get it ? thanks

    Hi here are a couple of links you may find useful, the first is if you have made a time machine backup, the second if you have not.
    http://osxdaily.com/2014/10/22/downgrade-os-x-yosemite-to-mavericks/
    http://www.macworld.co.uk/how-to/mac-software/revert-back-mavericks-from-yosemit e-3581872/

  • Tree like structure ??????????? pls help

    Hello
    I want to get the tree like structure
    My requirement is that when I write any jsp and put it in webapps's any
    folder I should get tree like structure of the folders in which I am putting my jsp.
    Foe example I have structure like
    webapps
    --rakesh_folder1
    --rakesh_folder2
    --rakesh_folder3
    ---rakesh_subfolder1
    ---rakesh_subfolder2
    ----(Here goes my jsp which would make to get sructure)
    ----my_other_file_1
    ----my_other_file_2
    When I type http://localhost:8080/rakesh_folder3/rakesh_subfolder2/jspname
    I want output as
    --rakesh_folder3
    ---rakesh_subfolder2
    ----my_other_file_1 (size of file) (time stamp)
    ----my_other_file_2 (size of file) (time stamp)
    How should I proceed ????????????????????
    Tx in advance
    Rakesh

    rakesh,
    see if you have tree structure like this
    C:\
    Vivek
    Rakesh
    then C:\ is the root from where you are starting.
    so just
    <html>
    <body>
    C:\
    &ampnbsp;&ampnbsp;&ampnbsp;Vivek
    &ampnbsp;&ampnbsp;&ampnbsp;Rakesh
    </body>
    </html>

  • DOES ANYONE HAS A PROBLEM WITH A FAN NOISE LIKE A METAL BEARING

    I want to know if there is a problem with some of you that have a 20 inch early Imac I got this imac last june and now I begin to hear a hizzing noise like if it was a fan bearing or something.

    The drive is in the area where the vent grill is above the plug. There is a very low level disk "activation" noise (sort of a faint ticking type of sound) whilst it is working but then stops, where as the fans again very low noise can be heard all of the time - just. I sit about 650 to 700mm from the machine.
    The drive is only a manmade item and occasionally one will start to fail early in life. Today is unlike the old days where a vari-speed floppy drive could need changing every month if worked in a commercial environment and a hard drive wasn't much better.
    chris

  • Problem with a long tracks like audiobooks, half or more then hour

    Please, help me to solve the problem with forwarding or other navigation with long tracks... when i try to forward some long track my ipad do it with repeating of short pieces of that track, twice or more... but the time counter are working correctly and count all the time. At last i have a track forwarded to the midlle or less but ipod thinks that is the end of the track and switching to the next

    Rustam,
    I think the best way to do it is to create linking text boxes, so that the overflow of text from one box appears in the linked box on the next page.
    To do this, go to View > Show Layout, then click in the gray margin area to make your cursor disappear. Now when you insert a text box, it will be defined as Fixed On Page, allowing you to move it wherever you want. Insert the first box, then click on the little blue "ear" on the lower right of the box. That will create a second, linked box. Drag that second box to the next page. Move and expand the two boxes as needed.
    Adding a background color to text is easy. Whether the text is on the main text layer or in a text box, highlight the text, click on the Text inspector > More button, then check the Paragraph Fill box. From there, click on the color box, crayons, then choose the color you want in the background. Drag that color from the swatch into the paragraph.
    -Dennis

  • I am having ongoing connection problems with the Clash of Clans app which means that I lose battles, resources or boost times. This results in a loss of gems which I have purchased but will not be refunded as they will not accept responsibility.

    Whilst playing Clash of Clans I will continually lose the internet connection. This means that I lose battles, resources, gold etc and lose boost times. I have informed Supercell who blame my internet connection even though the iPhone, laptop and TV all work fine so it is obviously a technical problem with their game and probably something to do with their last updates.
    As I have purchased gems I feel that I should be compensated for my loss but they will not accept responsibility nor investigate the technical issue. The loss of connection occurs constantly with the game often freezing during replays or searching for battles. This is obviously not a connection issue.
    What suggestions do you have to resolve this situation?

    Hi.
    Thanks for the reply. I asked because I also wanted to see if others had encountered the same problem.
    I have no problems with my internet connection as I run my TV, laptop and iPhone off the same connection with no problems. I believe that since the recent updates to the game this has caused the problem. The game often freezes, cancels out or returns me to the main game screen during battles or replays.
    What I want to know is how do I get the game designers or owners to acknowledge my problem as at this time they keep telling me it is my internet that is a problem and not their game. How do they know this when they refuse to investigate. What can I do and who do I go to for support if they won't accept responsibility?
    I am very grateful to you for replying but concerned that if this can happen to me then how many other gamers are losing out and paying for something that they are not going to receive.
    Many thanks.

  • My iphone 4 was crushed on the road.  Bought a 4 replacement tried to restore it in itunes to get my contact info and it said there was a problem with my phone and I should contact mean

    My iphone 4 was crushed on the road.  Bought a 4 replacement tried to restore it in itunes to get my contact info and it said there was a problem with my phone and I should contact apple store.  What does that mean please?

    Is the replacement exactly the same as the original ie same memory size & same version? If so it may require updating the OS software before trying to restore your stuff from the backup.

  • Hierarchical Tree Like Structure with DataTableEx jsp Component

    Hi,
    I have created a dataTable component with rowcategory on 2 columns to get the nesting effect on the data rows with check boxes . Initially everything is collapsed. Once i select few checkboxes and then click on "Clear Selection " btn to clear off all the selection, the entire the nesting again collapses.
    Can any one suggest how can i prevent this from happening. Also i need to implement an Expand All and Collapse All feature separetely. How can i do this.. I am not using a tree component because i have few text fields and checkboxes for each row. Would be highly grateful if someone could suggest a way or piece of code

    Hi,
    I have created a dataTable component with rowcategory on 2 columns to get the nesting effect on the data rows with check boxes . Initially everything is collapsed. Once i select few checkboxes and then click on "Clear Selection " btn to clear off all the selection, the entire the nesting again collapses.
    Can any one suggest how can i prevent this from happening. Also i need to implement an Expand All and Collapse All feature separetely. How can i do this.. I am not using a tree component because i have few text fields and checkboxes for each row. Would be highly grateful if someone could suggest a way or piece of code

  • Trying to import a weird table format into a tree like structure.

    Hi All,
    I am using NWDS 7.0.18
    I am trying to use the Tree in a table element to organize some data I'm receiving from an rfc. The table im receiving looks a little like this:
    leaf1  |  leaf2 |  root  |  child1 |  child2  |
    00     |  ab    |   r      |  c1a    |  c1a_1  |
    00     |  cd    |   r      |  c1a    |  c1a_2  |
    01     |  ab    |   r      | c1b     |  c1b_1  |
    01     |  cd    |   r      | c1b     |  c1b_2  |
    This table can grow and shrink in terms of children but the lowest child with data will always have leaves.
    Now heres what I'm finding difficult. When I loop thru this table in Web Dynpro, when i get the first element with getElementAt(i), it returns the entire first row.
    The wdInit method calls a custom method like this
    addLevelEntries(wdContext.nodeLEVEL(), "ROOT");
    And then later in onActionLoadChildren
    public void onActionLoadChildLevelEntries(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent, com.sjm.wdp.wdp.IPrivateTreeAppCompView.ILEVELElement element )
        //@@begin onActionLoadChildLevelEntries(ServerEvent)
        addLevelEntries(element.nodeCHILD_LEVEL(), element.getID());
        element.setChildrenLoaded(true);
        //@@end
    but the problem is the child element Id's are in the same row as root element id!!!!
    How can I, if possible, loop thru this table and add the relevant nodes in the correct places and then eventually add its leaves?
    Any help greatly appreciated.
    Thanks
    P

    //why not making use of the Search feature of this forum //
    DVDs are in a socalled delivery format (mpeg2), which isn't meant and made for any processing as editing...
    for using the iLife apps, you have to convert'em first, in recommended order, choose one of the following tools/workarounds:
    DVDxDV (free trial, 25$, Pro: 90$)
    Apple mpeg2 plugin (19$) + Streamclip (free)
    VisualHub (23.32$)
    Drop2DV (free, requires installation of ffmpeg parts, google for it...)
    Cinematize >60$
    Mpeg2Works >25$ + Apple plug-in
    Toast 6/7/8 allows converting to dv/insert dvd, hit apple-k
    connect a miniDV Camcorder with analogue input to a DVD-player and transfer disk to tape/use as converter
    http://danslagle.com/mac/iMovie/tips_tricks/6010.shtml
    http://danslagle.com/mac/iMovie/tips_tricks/6018.shtml
    http://karsten.schluter.googlepages.com/convertdvdstodvs
    none of these methods or tools override copy protection/DRM mechanisms.. advice on 'ripping' is a violation of the ToU of this board ..
    +be nice to copy rights ...+

  • Problem with derived column

    Hi friends,
    [Reports 6i - 6.0.8.20.1 & DB 9.2.0.8 ]
    I have problems in one report to rerieve the value of a column in my Query1 in a derived column.
    Let's say that we have a query (Q1) that obtain the departments of a company.
    And a second query that obtain certain data for each department of Q1 and (this is important) we can't (due to others requirements) use a "link" to join the querys.
    So my idea was to create a formula column (FC1) in Q1 where the departement is stored... and, out of the query, create a derived column that would have the value of FC1.
    Then ... in design model... I'll have 2 repeating frames... one based on Q1 and other based on Q2..
    Q1 Frame is ok and shows all departments... but... Q2 repeating... only shows values for 1 department... So my derived column seems not to change when the value of FC1 changes...
    Any ideas?
    Thanks,
    Jose

    If your query1 is something like
    SELECT ...
    d.deptno,
    FROM
    ...dept d
    WHERE ...
    and you want to do query2
    SELECT ...
    FROM ...
    for all departments but then split the output on display by department.
    I'd go with the suggestion from the other poster above:
    Do your query1 as
    SELECT ...Query1Fields,
    Query2Fields
    FROM Query1Tables, (put query2 here) q2
    where q2.deptno = dept.deptno -- or whatever the conditions are
    Or use
    WITH q2 AS (put query2 here)
    SELECT ...Query1Fields,
    Query2Fields
    FROM Query1Tables, q2
    where q2.deptno = dept.deptno -- or whatever the conditions are
    That second format should ensure that query2 is done as one whole unit.
    Then in the data model drag and drop the query2fields outside the query1 group to form a new group below it. Then in the layout you have a repeating group based on the query1 group and within it a repeating group based on the new "query2" group.

  • Huge problems with my MacBook:  Invalid Node Structure and More!

    A couple days ago I was browsing the internet, and when I closed Safari, the system froze. I couldn't even force quit out of anything, so I had to shut it off manually. When I tried to turn my computer back on the next day, I couldn't get past the Apple screen. The little wheel would keep spinning, but I could never get anywhere.
    Then, I tried to boot from the Leopard DVD to possibly reinstall Leopard, hoping it would work. At first, no drives would show up to install to, but for some reason, they eventually showed up. Problem is, I don't have enough free memory to reinstall Leopard. Furthermore, I've tried to fit it on the space I have, and it says that the install failed, so I can't reinstall Leopard.
    I also went to Disk Utility from the DVD and tried to repair the disk. The only option available was to Verify Disk, but when I go there, that fails, and it says "invalid node structure."
    I'm not sure what happened to my computer because it seemed to come from nowhere. To sum up, I cannot log in to OS X, or even XP on a separate partition, I can't reinstall Leopard, and I can't repair the disk. I've read about how DiskWarrior might help, but I can't get in to OS X. Does anyone have any idea what happened or what I can do? I haven't backed anything up, so if I'm screwed, then so be it, I guess. Just wondering if anyone has any explanations or suggestions. Thanks.

    Interesting how many people have this same issue. A friend of mine has brought me her white Macbook Intel Core 2 with Leopard and it had a folder with a question mark instead of the apple at startup. I was able to boot using the Mac Install DVD and ran Disk Utility. It said something like "Invalid Node Structure" and "Cannot Repair". Unfortunately DiskWarrior will not fix this. I tried it to no avail. I'm resigned to the fact that a new hard drive is necessary.
    The HD in there is a Hitachi 120GB.
    It also wouldn't let me erase the disk nor partition it. Then, one morning I woke up and it was able to erase! So I erased, then installed Tiger. It seemed to be working fine. So I rebooted from the Leopard drop-in disk and installed Leopard. Then I restarted, and BAM! back to the question mark folder. Now I'm back to where I started. Other threads
    I forgot to mention that my friend had photos and music on the HD that she couldn't do without and I was able to recover that data using Data Recover II. First I had to use SuperDuper to clone my own computer onto an external drive so I could use it as a boot drive.
    For now the only solution is to buy a new internal hard drive and reinstall the OS. And regularly backup!!
    So I guess this issue has not really been solved, but hopefully you have warranty. Unfortunately for my friend, this happened a week after her warranty expired.
    Good luck.

Maybe you are looking for

  • (SOLVED) Pacman error: GPGME does not exist

    Hi, I have also just been struck with the same issue - a broken pacman (and for no reason that I can fathom). Was working perfectly yesterday and all I did that wan't usual was to uninstall clamav. Anyway, I have read this post and done a pacman -Syy

  • Display files

    What's wrong with the following when it wont display a list of files All I get is a blank page! <HTML> <head> <script> function dis() </script> </head> <BODY> <%@ page language="java" import="java.util.Date" %> <% java.io.File f=new java.io.File("c:\

  • HP Deskjet 3054 driver not up to date

    So I just bought a MBA and they gave me a printer for free. Problem is, the driver is out of date. I have the HP Deskjet 3054 Anyone else? What should I do?

  • Backlight wont stay on

    I have a Touchsmart 310 that runs windows fine but the backlight does not stay on.  I set up an HP service but I see that the customer service tech wrote "MOTHERBOARD NO VIDEO" in my complaint. I want to be sure they are addressing the right problem

  • I have forgotten my password to unlock my iPhone backup

    While upgrading my operating system and applications I had to restore my phone (via iTunes) from the back up on my computor. I am being asked for a password to unlock my iPhone backup but cannot remember it. How can I get the password or access the b