Get the parent-child hierarchy of column delimited

I've been on this forum once before, and someone helped me, so I hope I can get help again!

4-15-5987');

Thus, the hierarchy is divided on the hyphen. first parent being 4245, then the next value is-4 (including the hyphen) and what follows is - 1, for example

CREATE TABLE REGEXTEST
  ( ITEM VARCHAR(20)); 

  INSERT INTO REGEXTEST (ITEM) VALUES ('4245-4');
  INSERT INTO REGEXTEST (ITEM) VALUES ('4245-4-1');
  INSERT INTO REGEXTEST (ITEM) VALUES ('4245-4-10');
  INSERT INTO REGEXTEST (ITEM) VALUES ('4245-4-11');
  INSERT INTO REGEXTEST (ITEM) VALUES ('4245-4-12');
  INSERT INTO REGEXTEST (ITEM) VALUES ('4245-4-13');
  INSERT INTO REGEXTEST (ITEM) VALUES ('4245-4-14');
  INSERT INTO REGEXTEST (ITEM) VALUES ('4245-4-15');
  INSERT INTO REGEXTEST (ITEM) VALUES ('4245-4-15-59A7');
  INSERT INTO REGEXTEST (ITEM) VALUES ('4245-4-15-59D7');
  INSERT INTO REGEXTEST (ITEM) VALUES ('4245-4-15-59F7');
  INSERT INTO REGEXTEST (ITEM) VALUES ('4245-

I have to be able to bind-1, -4, 4245. Perhaps the simplest is to build a new table with a primary key where it is assigned the id of the parent to the child.
I just can't understand how to divide the individual elements and maintain the hierarchy. As previously mentioned, someone helped me with another part of the problem before where I needed to maintain the entire path of each child with the following query:

select  nvl(prior item,item) parent,
        nvl2(prior item,item,null) child
  from  REGEXTEST
  connect by substr(item,1,instr(item,'-',-1) - 1) = prior item
  order by child,parent

Now, if I could extrapolate that into a new table:

CREATE TABLE FileHierarchy
(ItemID INT NOT NULL PRIMARY KEY,
ItemName varchar(50) NOT NULL,
ParentID INT NULL);

ItemName is the 4245 or - 4 or - 1 (only) - Yes, including the hyphen.

The ID of the parent-1 would be the ID-4, etc...

Thank you very much in advance!

J.F. Larente

Solution for not having stored the high level:

SQL > select *.
regextest 2
3.

POINT LEV
-------------------- ----------
4245 4
4245 4-1
4245 4-10
4245 4-11
4245 4-12
4245 4-13
4245 4-14
4245 4-15
4245 4-15-59 A 7
4245 4-15-59 D 7
4245-4-15-59F7

11 selected lines.

SQL > with t1 as)
2. Select item
regextest 3
4 Union all the
5 select distinct substr (item, 1, instr(item,'-',1))
6 of regextest
7             ),
8 t2 as)
9. select element,
10 row_number() on id (order by article)
11 from t1
12              )
13. select id,
14 regexp_substr (rtrim (point,'-'), case level when 1 then ' [^-] + $' other '-[^-] + $' end) child.
parentID 15 prior id,
16 regexp_substr (prior rtrim (point,'-'), case level - 1 when 1 then ' [^-] + $' other '-[^-] + $' end) parent
17 of t2
beginning 18 with substr(item,-1) = '-'
19 connect by substr (item, 1, instr(item,'-',-1) - 1) = prior rtrim(item,'-')
20 and article! point prior =
21.

ID PARENTID PARENT CHILD
---------- -------------------- ---------- --------------------
1 4245
2 -4                            1 4245
3 -1                            2 -4
4 -10                           2 -4
5 -11                           2 -4
6 -12                           2 -4
7 -13                           2 -4
8 -14                           2 -4
9 -15                           2 -4
10-59A 7 9-15
11 59 D 7 9 - 15

ID PARENTID PARENT CHILD
---------- -------------------- ---------- --------------------
12 59F7 9-15

12 selected lines.

SQL >

SY.

Tags: Database

Similar Questions

  • Get the Parent for each record in the child

    Dear Experts,

    I have a table that contains the parent and child information. I need to make a request to get the parents of each book of the child table. I tried to write the query but does not get the expected results. Please help me.

    Table: relationship

    Parent of the child

    102 101

    103 102

    104 103

    106 105

    107 106

    109 108

    110 109

    Output:

    Expected child

    102 101

    103 102; 101

    104 103, 102, 101

    106 105

    107 106; 105

    109 108

    110 109

    Thank you very much

    Hello

    MU * 443499 * TR wrote:

    Dear Experts,

    I have a table that contains the parent and child information. I need to make a request to get the parents of each book of the child table. I tried to write the query but does not get the expected results. Please help me.

    Table: relationship

    Parent of the child

    102 101

    103 102

    104 103

    106 105

    107 106

    109 108

    110 109

    Output:

    Expected child

    102 101

    103 102; 101

    104 103, 102, 101

    106 105

    107 106; 105

    109 108

    110 109

    Thank you very much

    Why do you want to

    Expected child

    -----  ---------------

    110 109

    Instead of

    Expected child

    -----  ---------------

    110 109; 108

    ?

    You may want something like this:

    CONNECT_BY_ROOT SELECT AS children

    SYS_CONNECT_BY_PATH (parent, ';')  AS expected_output

    FROM table_x

    WHERE CONNECT_BY_ISLEAF = 1

    CONNECT BY child = parent PRIOR

    ;

    If you would care to post CREATE TABLE and INSERT statements for your sample data, and then I could test this.

  • Default filters that users can delete (in the parent/child Setup)?

    Is it possible in Latitude 2.2.2 to have filters (filters of the range, refinement filters etc.) applied by default (which means that users see these filters when they log-in), but they can also remove (using bread crumbs portlet) if they wanted to? We tried to use the source of data (JSON) filters (using 'baseFunctions' setting) where we have a parent/child Setup, but it seems these filters cannot be removed once applied. Note that filters can be removed if we do not have a parent/child relationship between the data sources, but as soon as we introduce a parent/child relationship between the data sources (which we need), the GET of sticky filters and cannot be deleted. Any reason why the parent/child relationship causes the filters becoming sticky? Any way (alternate) to reach what we want?

    I think that it is a known problem (LSTUDIO-5088) and there could be a fix for this. You can contact technical support to obtain the fix.

    Dave

  • Simulate the 1 - N N - N relationship using the Parent-child structure

    Hello

    I have a 1-N relation between SKILL tables and the USER, which means 1 skill can be applied to multiple users. A jurisdiction may have a parent jurisdiction, which means that a ParentSkill inherits all the privileges of his child.

    I would like to simulate a N - N relation between the users and the skills by building a vision that goes through the parent-child relationship. This is possible for the construction?


    Current structure:
    |USERID | USERNAME | SKILLID  |
    +-------+----------+----------+
    |   1   |  Jack    |      1   |
    |   2   |  Simon   |      1   |
    |   3   |  Fred    |      3   |
    +-------+----------+----------+
    
    
    |SKILLID | DESCRIPTION   | PARENTSKILL  |
    +--------+---------------+--------------+
    |   1    |  Mechanic     |      2       |
    |   2    |  Inspector    |      3       |
    |   3    |  Supervisor   |      null    |
    +--------+---------------+--------------+
    Favorite exit (the skillid order is not important):
    |USERID | USERNAME | SKILLID  |
    +-------+----------+----------+
    |   1   |  Jack    |      1   |
    |   2   |  Simon   |      1   |
    |   3   |  Fred    |      3   |
    |   3   |  Fred    |      2   |
    |   3   |  Fred    |      1   |
    +-------+----------+----------+

    I hope that answers your needs:

    WITH
    users as
    (
        SELECT 1 as USERID, 'Jack' as USERNAME, 1 as SKILLID FROM DUAL UNION ALL
        SELECT 2 as USERID, 'Simon' as USERNAME, 1 as SKILLID FROM DUAL UNION ALL
        SELECT 3 as USERID, 'Fred' as USERNAME, 3 as SKILLID FROM DUAL
    ),
    skills as
    (
        SELECT SKILLID,CONNECT_BY_ROOT SKILLID AS ANCESTORS
        FROM
            (
                SELECT 1 as SKILLID, 'Mechanic' as DESCRIPTION, 2 as PARENTSKILL FROM DUAL UNION ALL
                SELECT 2, 'Inspector', 3 FROM DUAL UNION ALL
                SELECT 3, 'Supervisor', NULL FROM DUAL
            )
        CONNECT BY PRIOR PARENTSKILL = SKILLID
    )
    SELECT USERID,USERNAME,ANCESTORS
    FROM skills, users
    WHERE users.skillid = skills.skillid
    /
    
        USERID USERN  ANCESTORS
    ---------- ----- ----------
             1 Jack           1
             2 Simon          1
             3 Fred           3
             3 Fred           2
             3 Fred           1
    

    I hope this helps!

  • Re: Query hierarchy to get the parent nodes?

    Guys I need a help here please...

    I want to ask using any unique value for example in where clause for 'E', I get a lot of 'A' to 'G', which are all related. is there a way to do this?...

    IM lookking as

    A

    B

    C

    D

    E

    F

    G

    When I search for 'E '.

    Thanks in advance...

    Hello

    The design of your table is complicating the problem.  If your data is a tree (that is, if each node can have, at most, only one parent) then it would be simpler to have a separate table for each node, if this node has a parent or not. in other words, add a line like

    Insert into RELATIONSHIP (PARENT, CHILD) Values (NULL, 'A');

    You can create a unique constraint for CHILD.

    If you must use the existing design of the table, here's a way to do it:

    WITH roots AS

    (

    SOME parents

    IN the relationship

    WHERE CONNECT_BY_ISLEAF = 1

    START WITH IN '& required' (parent, child)

    CONNECT BY child = parent PRIOR

    )

    SELECT parents as a node

    Roots

    UNION

    SOME children as a node

    IN the relationship

    START WITH (IN) parent

    SOME parents

    Roots

    )

    Parent child = PRIOR CONNECTION

    ORDER BY node

    ;

    That's essentially what Blushadow posted and also what Chris suggested, but as the Blushadow request, the request of bottom-up is only encoded only once and the target node (& required in this query) is used only once.

  • Get the parent in the child VO inst value

    I have a master detail on the page and in a column of vo child I want to display the current line of a master vo.

    Then, how to refer to the master vo-current rank in the child attribute in line on UI? in the same fields vo can be accessed as #{rank. AttrbiuteName.inputValue}

    Maybe this can help: http://www.gebs.ro/blog/oracle/adf-bc-viewlink-viewlinkaccessor-and-groovy/
    or you can bind the value property in the retail method column in managed bean that can extract value iterator parent, something like this:

    public String getSomeFieldFromParent(){
        return (String)ADFUtils.findIterator("parentIterator").getCurrentRow().getAttribute("SomeAttribute");
    }
    

    Dario

  • Get the parent (paragraph) of the text

    Hi all

    I met a problem and can't seem to find the solution myself. It's like this:

    Let's say you have a story with two paragraphs. A paragraph has 'Hello' in it and the other a 'world' in as text.

    You can select e.g. 'Hello', then click on a button, and then after clicking on the button change for example "Hello".

    So you have a paragraph with "Greetings" and the other with the "world".

    Now, I have the following code I need to change:

    selectedContent var = app.selection [0] .silence; It's selection, "Hello".

    var contentToChange = app.selection [0] .parent; This is the story.

    I want to contentToChange be the paragraph in the text.

    .parent Gets the story, so everything disappears and becomes just "Hello".

    Tried a lot of things, but impossible to find the solution (what should I use instead of 'parent' to get the paragraph).

    Can anyone help please, thank you in advance

    Greetings

    contentToChange = app.selection [0] .paragraphs [0]

    is what you are looking for

  • How to get the value of a particular column column name?

    Hi all

    How to get the column name for a particular column value.
    example:

    create table test (ID number, col2, col3 varchar varchar);

    Insert into test values (1, 'true', 'false');
    Insert into test values (2, 'false', 'true');
    commit;

    I want to choose the name of the data column 'true' with id = 1;

    That is to say) while waiting for answer is "col2". pls help someone.

    This might help:

    DECLARE
       c1 SYS_REFCURSOR;
    BEGIN
       OPEN c1 FOR
       SELECT col2,
              col3
       FROM   test
       WHERE  id = 1;
       --
       FOR c IN (SELECT rownum rn,
                        t2.column_value.getrootelement() name,
                        EXTRACTVALUE(t2.column_value, 'node()') value
                   FROM TABLE(XMLSEQUENCE(c1)) t,
                        TABLE(XMLSEQUENCE(EXTRACT(column_value, '/ROW/node()'))) t2)
       LOOP
          IF c.value = 'true' THEN
             DBMS_OUTPUT.PUT_LINE(c.name);
          END IF;
       END LOOP;
    END;
    
  • How can I can get the webBean child "Component of messages" of "petition".

    Hello

    I have a "component Message page layout: get" in a "Query: query region. How can I can get the child object of "component Message layout: look for ' webBean of the controller class" Query: query region "to add my OADefaultListBean?

    Thank you very much

    Hello

    --> Get the id of the layout of the message component
    --> Manager of bean for this presentation get the component messages using code lone below

    OAMessageComponentLayoutBean bean1 = (OAMessageComponentLayoutBean) webBean.findChildRecursive (id);

    --> now add your beans to list by default to this presentation of messagecomponent

    Kind regards
    Vijay Reddy.

    Published by: user10496887 on Sep 6, 2011 14:29

  • Need help with Javascript to get the value of standard report column

    Hi all

    Apex 3.1 version

    I have a query SQL (editable report) region where I need to do validations using a process of OnDemand and javascript. For this posting, I need to use the serial number and id of this same report line item. The function is called when the serial number is changed. I can get the serial number easily because it is a text field, however, the item id is a standard report column (which actually a text field or hidden gives me a checksum error, long story). How can I get the value of the standard report column to set the value of an element of the Application to use in my process of application as well as the serial number? Here is my code below.
    <script>
    
    function f_ValidateSerial(pThis)
    {
        
      // The row in the table
    
      var vRow = pThis.id.substr(pThis.id.indexOf('_')+1);
    
        //alert('Row is '+vRow);
    
    
      // Display the serial number
        //alert('The Serial Number is '+html_GetElement('f21_'+vRow).value);
    
      
     var get = new htmldb_Get(null,&APP_ID.,'APPLICATION_PROCESS=ValidateSerial',0);
     get.add('F101_SERIAL_NUMBER',html_GetElement('f21_'+vRow).value);
     get.add('F101_INVENTORY_ITEM_ID',+html_GetElement(?????+vRow).value);   // Here's where I need to get the item id to set application item!!
     
     gReturn = get.get();
     
    if (gReturn)
        { 
          alert(gReturn);
        }
     
      if(gReturn)
        { 
          html_GetElement('f21_'+vRow).value = '';
        }
               
    }
    </script>

    Hello

    Ok

    Item ID is standard report column.
    If you enter this Expression HTML column

    #ITEM_ID#
    

    I guess that the substitution of column item Id is #ITEM_ID #.

    Now, you have hidden input form that is not submitted.
    Then in JavaScript

    get.add('F101_INVENTORY_ITEM_ID',+html_GetElement('item_id_'+Number(vRow)).value);
    

    Kind regards
    Jari

  • get the parent movieclip name

    using the MovieClipLoader, everything works fine.

    fixation of a series of clips with a nested element and loading a jpg in each clip nested these MovieClip.

    in the func onLoadInit listener, I passed the name of the element that is responsible, how carefully I reference the parent of this element?

    Currently I can get the name nested mc (I just use target_mc as the use of help files), but you need to refer to its parent.
    THX!

    Have you tried target_mc._parent

  • Update the data to uppercase in the parent/child tables

    Hi gurus!

    In production, we have a table product and that is in reference by many tables making parent child relationship. By mistake, we realized last month some products have been added to lowercase and now we have a request to update all these product codes uppercase so that existing code that use these tables have no impact. Appreciate if you can give an idea about how can I update the existing data in the table parent uppercase as well as child records?

    Concerning
    Sri

    Are the product code that you need to update what is stored in the tables of children? If Yes, then you must do it in several steps, something like:

    Identify the child tables

    SELECT table_name, constraint_name
    FROM user_constraints
    WHERE r_constraint_name = (SELECT constraint_name
                               FROM user_constraints
                               WHERE table_name = 'PRODUCT_TABLE' and
                                     constraint_type = 'P');
    

    Create new product of upper-case code in the product table:

    INSERT INTO product_table
    SELECT UPPER(product_code), other_columns
    FROM product_table
    WHERE product_code <> UPPER(product_code);
    

    Update the children tables for caps product codes

    UPDATE child1
    SET product_code = UPPER(product_code)
    WHERE product_code <> UPPER(product_code);
    

    Finally, remove the tiny product_table product codes

    DELETE FROM product_table
    WHERE product_code <> UPPER(product_code);
    

    John

  • How can I get the parental control?

    I want to set up parental controls, but when I go into my control panel find the sound icon is not there and I went looking and looking but nothing came.

    Windows XP is not the Parental control.  This feature has been added in Windows Vista.

    XP can use Internet Explorer Content Advisor and allows to control the time that users can connect to.

  • How to get the Max value with other columns data also.

    Suppose that a query is covered with the data as

    Time of ID
    01 07/12/2014
    02 07/05/2014
    03 16/07/2014
    04 07/07/2014

    I need to get the ID and time to time max.
    that is, should I get
    Time of ID
    03 16/07/2014

    To do this, I wrote a query that gives me necessary data. But I thought that's the best way?
    Is it an effective way to get this data?
    My query that returns the data required is:

    SELECT ID, MAX_DT FROM
    (
    Select 'DUMMY', ID, TIME1, MAX (TIME1) OVER (PARTITION 'DUMMY') AS MAX_DT FROM TAB1
    WHERE ID IN (BLAH BLAH)
    )
    WHERE MAX_DT = (EDT) 1

    Frank mentioned links


    WITH test_data (id, time) LIKE)

    SELECT 01, to_date('2014/07/12','yyyy-mm-dd') FROM dual

    UNION ALL

    SELECT 02, to_date('2014/07/16','yyyy-mm-dd') FROM dual

    UNION ALL

    SELECT 03, to_date('2014/07/16','yyyy-mm-dd') FROM dual

    UNION ALL

    SELECT 04, to_date('2014/07/07','yyyy-mm-dd') FROM dual

    )

    SELECT id, time

    go (select id,

    time,

    Max (Time) on latest_time (order by time lines between unbounded preceding and following unbounded)

    of test_data

    )

    where time = latest_time

    ID TIME
    3 16/07/2014
    2 16/07/2014

    Concerning

    Etbin

  • How to get the use of database tables/columns in the table of edge/analysis?


    Hi all

    Anyone has an idea on how to get the tables in DB/colomns usaged in edge/analysis table in OBIEE 11 G?

    Thanks in advance!

    Anne

    You can try to generate a report of Catalog Manager for analysis / SA want to create the line and your RPD you can go to utilities > documentation of the repository and get the domain you want to and get all the mappings in Excel format.

    I hope this helps.

    SVS

Maybe you are looking for

  • Enter new credit card information

    Old card expired iPhone 6 won't let me enter the new credit card info to buy apps.

  • R8500 Firmware MU-MIMO

    The recent firmware has no option to activate MU-MIMO. This option is only with the firmware.28 and the beta version I have. I am told that the latest firmware has indeed HELPED MU-MIMO. Is this true? or did the version having the box turn on in adva

  • With POWER record pistol grip

    Anyone has a suggestion for a pistol grip that gives a button record boost? Would need a cable that plugs into the remote port? I will be essentially documentary shooting with the F55 with lots of the handheld and the current position of the record b

  • Information on battery - Pavilion 15 Notebook PC

    After charging my laptop battery to full, I unplugged the AC adapter / CC & continued to use the battery system. After an hour or two the remaining charge of % become 70%. Could someone please tell how I can collect information about the exact durati

  • 80030007 error code when you try to download updates for iget.

    Windows will not windows updates download