Oracle query convert recursive parent-child level columns

Dear gurus,

I have a Hyperion extracted dimension table with my COA in a parent/child layout:

parent, child

Acc01, acc001

acc001, acc0001 etc.

I need to convert to the:

level 2, level 1, Level0

Acc01, acc001, acc0001 etc.

Please advise, need to feed table table schema for reporting.

Concerning

Yannis

with

data in the form of

(select "C01" parent, child 'C001' Union double all the)

Select 'C001', 'C0001' from dual union all

Select 'C001', 'C0002"dual union all

Select "C01", "C002' from dual union all

Select "C0001', 'C00001' from dual union all

Select "C00001', 'C000001' from dual union all

Select 'C000001', 'C0000001' from dual

)

Select leve1_1, level_2, level_3, level_4, level_5, level_6

from (select root0, lvl0, regexp_substr(path,'[^,]+',1,level) VAC, level lvl

of (lvl0 level select,

connect_by_root parent root0,

parent connect_by_root | path of SYS_CONNECT_BY_PATH (Child, ',')

from the data

where connect_by_isleaf = 1

Start with parent (select parent

data d

If not exists (select null

from the data

where child = d.parent

)

)

connect by prior child = parent

)

connect by level<=>

and prior root0 = root0

and prior lvl0 = lvl0

and prior sys_guid() is not null

)

Pivot (max (VAC) for lvl 1 as leve1_1, 2 level_2, 3 level_3, 4 level_4, 5 level_5, 6 level_6)

LEVE1_1 LEVEL_2 LEVEL_3 LEVEL_4 LEVEL_5 LEVEL_6
C01 C002 - - - -
C01 C001 C0002 - - -
C01 C001 C0001 C00001 C000001 C0000001

Concerning

Etbin

Tags: Database

Similar Questions

  • MDX query to display parent-child combination

    Hi guys...
    I am really new to Essbase technology.
    Could you please help me with this one:
    is it possible to extract data (for example the metadata of a contour)... for example:-
    The hierarchical structure is as follows:
    A1
    A11
    A12
    A2
    A21
    A22
    I want a MDX query to display as:
    A1 A11
    A12 A1
    A21 A2
    A22 A2
    I tried different ways but could not come up with a request for it.
    Thanks in advance for your help.

    This may mean a wrong path, I performed just following on the server - essbase

    export sample.basic contour all dimensions to xml_file 'c:/temp/outline.xml ';

    See you soon

    John
    http://John-Goodwin.blogspot.com/

  • Hierarchy parent child scenario

    Hi friends,

    Im just working on the parent-child hierarchy by using the link below with the sample data.

    http://www.Oracle.com/WebFolder/technetwork/tutorials/OBE/FMW/bi/bi11115/biadmin11g_02/biadmin11g.htm_

    I tried to implement the same hierarchy using my local data instead of referring to the sample data.

    I have a query that returns the Manager as well as the position of the employee at the employee below
    select distinct papf.person_id,  papf.full_name "Employee Name", supf.person_id "Manager Id", supf.full_name "Manager Name", pj.name "Position Name"
    from per_all_people_f papf, per_all_assignments_f paaf, per_all_people_f supf, per_jobs pj
    where papf.person_id = paaf.person_id and supf.person_id = paaf.supervisor_id and paaf.job_id = pj.job_id
    and trunc(sysdate) between paaf.effective_start_date and paaf.effective_end_date and 
    trunc(sysdate) between papf.effective_start_date and papf.effective_end_date
    Im looking forward to implement the same result in my BI with a parent-child hierarchy.

    Since then, I imported three tables to my physical layer
    per_all_people_f------------Dimension
    per_all_assignments_f-----Fact
    per_jobs---------------------Dimension
    For the creation of parent-child in BI, we need to have a table of separate Parent child which consist of four columns like ancestorkey, memberkey, distance, sheet.

    In the column above, I can understand the meaning as
    For Ancestorkey-->Managerid
    Memberkey------->Employeeid
    But I could not the meaning of the column distance as the meaning suggest, as a distance b/w the two column of the worksheet in the sense suggest as one sheet What leaf member it refers.

    I also have the link below then too could not get the feel for it

    http://www.rittmanmead.com/2010/08/Oracle-BI-EE-11g-Parent-Child-Hierarchies-Differing-Aggregations/+.

    How do I train the child parent table for the BI of my three tables above in the HRMS.

    Thank you

    Kind regards
    Saro

    Hi friends,

    I think I found a link to

    http://prasadmadhasi.com/2011/11/15/hierarchies-parent-child-hierarchy-in-OBIEE-11g/

    Let me try this and will update accordingly.

    Thanks for your point of view.

    Kind regards
    Saro

  • Error with BIEE11.1.1.5 Parent-child hierarchies

    Hello

    I use BIEE11.1.1.5, I created a logic Dimensions with Parent-child hierarchies.

    In response, I move named 'H5 Sales Rep' hierarchies, and then display the results,

    There error, the following error message:

    ODBC driver returned an error (SQLExecDirectW).
    Error details
    Error codes: OPR4ONWY:U9IM8TAC:OI2DL65P
    State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error occurred. [nQSError: 43113] The message returned by OBIS. [nQSError: 43119] Query Failed: [nQSError: 22056] to use the line functions, you must associate a Table close Source logical Table "LTS1 Sales Rep. (HY000)
    Publ. SQL: SELECT 0 s_0, "Sample Sales". "" Sales Rep ". "" Sales Rep Name ' s_1, CASE WHEN ISLEAF ("Sample Sales" "." ") Sales Rep. ("' H5 Sales Rep") THEN 1 ELSE 0 END s_2, IDOF ("Sample Sales" "." ") Sales Rep. ("' S_3 H5 Sales Rep"), PARENT ("" Sample Sales "". "") Sales Rep. ("' S_4 H5 Sales Rep") OF "Sample Sales" WHERE ISROOT ("" Sample Sales "". "") Sales Rep. ("' H5 sales representative")

    someone knows why?
    Thank you!

    Hi Leo,

    You have configured table of closing? http://www.rittmanmead.com/2010/11/Oracle-BI-EE-11g-parent-child-hierarchies-multiple-modeling-methods/

    Also, be sure to make the changes to hierarchy in offline mode.

    Kind regards
    DpKa

  • 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.

  • Stuck on a sql query to search for records that have the same parent child records

    Oracle 10 g 2 Enterprise Edition.

    Hello

    I'm writing a logic to find records in a parent table, who have the same values in a child table.
    This is part of a larger application, but I am stuck on that part for now, so I have mocked some of the below simplified tables to capture the heart of the
    the problem is that I'm stuck.
    Let's say I have a responsible parent, child employee table table and there are a number of many relationships between them.
    The aptly named Join_Table manages the relationship between them. If a manager can manage several employees, an employee can be managed by
    many managers.

    I have a feeling it's stupidly easy, but it seems to me having a bad episode of brain freeze today!
    -- parent table
    CREATE TABLE manager (
     id      number primary key,
     name      varchar2(100));
    
    -- child table 
    CREATE TABLE employee (
     id          number primary key,
     name      varchar2(100));
    
    -- link table
    CREATE TABLE join_table (
     manager_id          NUMBER, 
     employee_id      NUMBER,
     CONSTRAINT join_table_pk PRIMARY KEY (manager_id, employee_id),
     CONSTRAINT manager_fk FOREIGN KEY (manager_id) REFERENCES manager(id),
     CONSTRAINT employee_fk FOREIGN KEY (employee_id) REFERENCES employee(id) 
     );
    
    -- Insert some managers
    INSERT INTO manager (id, name) VALUES (1, 'John');
    INSERT INTO manager (id, name) VALUES (2, 'Bob');
    INSERT INTO manager (id, name) VALUES (3, 'Mary');
    INSERT INTO manager (id, name) VALUES (4, 'Sue');
    INSERT INTO manager (id, name) VALUES (5, 'Alan');
    INSERT INTO manager (id, name) VALUES (6, 'Mike');
    
    -- Insert some employees 
    INSERT INTO employee (id, name) VALUES (101, 'Paul');
    INSERT INTO employee (id, name) VALUES (102, 'Simon');
    INSERT INTO employee (id, name) VALUES (103, 'Ken');
    INSERT INTO employee (id, name) VALUES (104, 'Kevin');
    INSERT INTO employee (id, name) VALUES (105, 'Jack');
    INSERT INTO employee (id, name) VALUES (106, 'Jennifer');
    INSERT INTO employee (id, name) VALUES (107, 'Tim');
    
    -- Insert the links
    -- John manages Paul, Simon, Ken
    INSERT INTO join_table (manager_id, employee_id) VALUES (1, 101);
    INSERT INTO join_table (manager_id, employee_id) VALUES (1, 102);
    INSERT INTO join_table (manager_id, employee_id) VALUES (1, 103);
    -- Bob manages Paul, Simon, Kevin, Jack
    INSERT INTO join_table (manager_id, employee_id) VALUES (2, 101);
    INSERT INTO join_table (manager_id, employee_id) VALUES (2, 102);
    INSERT INTO join_table (manager_id, employee_id) VALUES (2, 104);
    INSERT INTO join_table (manager_id, employee_id) VALUES (2, 105);
    -- Mary manages Jennifer, Tim
    INSERT INTO join_table (manager_id, employee_id) VALUES (3, 106);
    INSERT INTO join_table (manager_id, employee_id) VALUES (3, 107);
    -- Sue manages Jennifer, Tim
    INSERT INTO join_table (manager_id, employee_id) VALUES (4, 106);
    INSERT INTO join_table (manager_id, employee_id) VALUES (4, 107);
    -- Alan manages Paul, Simon, Ken, Jennifer, Tim
    INSERT INTO join_table (manager_id, employee_id) VALUES (5, 101);
    INSERT INTO join_table (manager_id, employee_id) VALUES (5, 102);
    INSERT INTO join_table (manager_id, employee_id) VALUES (5, 103);
    INSERT INTO join_table (manager_id, employee_id) VALUES (5, 106);
    INSERT INTO join_table (manager_id, employee_id) VALUES (5, 107);
    -- Mike manages Paul, Simon, Ken
    INSERT INTO join_table (manager_id, employee_id) VALUES (6, 101);
    INSERT INTO join_table (manager_id, employee_id) VALUES (6, 102);
    INSERT INTO join_table (manager_id, employee_id) VALUES (6, 103);
    
    -- For sanity
    CREATE UNIQUE INDEX employee_name_uidx ON employee(name);
    If I ask for Manager John, so I want to find other managers who manage the exact list and even employees.
    Answer should be Mike.
    If I ask for Manager of Mary, the answer should be Sue.

    This query will give me the list of managers who manage some of the same employees as John, but not the same employees accurate...
    SELECT DISTINCT m.name AS manager
    FROM manager m, join_table jt, employee e
    WHERE m.id = jt.manager_id
    AND jt.employee_id = e.id
    AND e.id IN (
         SELECT e.id
         FROM manager m, join_table jt, employee e
         WHERE m.id = jt.manager_id
         AND jt.employee_id = e.id
         AND m.name = 'John')
    ORDER BY 1;
    I thought about using set operations to find managers with a list of employees less than my employees is null and where my employees under their list of employees is null. But there must be an easier way more elegant.
    Any ideas?
    BTW, I need to run as a batch on tables with > 20 million rows so the efficiency of queries is key.

    What about...

    WITH manager_list AS
    (
     SELECT name,
            LTRIM(MAX(SYS_CONNECT_BY_PATH(id,','))
            KEEP (DENSE_RANK LAST ORDER BY curr),',') AS employees
     FROM   (SELECT m.name,
                    e.id,
                    ROW_NUMBER() OVER (PARTITION BY m.name ORDER BY e.id) AS curr,
                    ROW_NUMBER() OVER (PARTITION BY m.name ORDER BY e.id) -1 AS prev
             FROM   manager m,
                    join_table jt,
                    employee e
      WHERE m.id           = jt.manager_id
      AND   jt.employee_id = e.id
      AND   m.name = :P_MANAGER)
      GROUP BY name
      CONNECT BY prev = PRIOR curr AND name = PRIOR name
      START WITH curr = 1
    ), all_list AS
    (
     SELECT name,
            LTRIM(MAX(SYS_CONNECT_BY_PATH(id,','))
            KEEP (DENSE_RANK LAST ORDER BY curr),',') AS employees
     FROM   (SELECT m.name,
                    e.id,
                    ROW_NUMBER() OVER (PARTITION BY m.name ORDER BY e.id) AS curr,
                    ROW_NUMBER() OVER (PARTITION BY m.name ORDER BY e.id) -1 AS prev
             FROM   manager m,
                    join_table jt,
                    employee e
      WHERE m.id           = jt.manager_id
      AND   jt.employee_id = e.id)
      GROUP BY name
      CONNECT BY prev = PRIOR curr AND name = PRIOR name
      START WITH curr = 1
    )
    SELECT a.*
    FROM   manager_list m,
           all_list a
    WHERE  m.employees = a.employees
    

    Would be easier in 11g, but I do not have a facility here so this is based on 10g.

    See you soon

    Ben

  • in the query and parent/child relationship

    WITH the data AS

    (

    SELECT '213NY1' lfrom, NULL, '215ZVD' mi lto, "215ZV9 ' id, 1 January 2014' sdate, January 2, 2014' edate, 3 January, 2014 'mdate' January 5, 2014 medate double UNION ALL.

    Lfrom SELECT NULL, '215ZVD' mi, id "213NY1", "215ZV9" lto 4 January 2014 'sdate', 6 January 2014 edate, January 7, 2014 'mdate', 8 January 2014 medate double UNION ALL

    SELECT '216TVZ' lfrom, NULL, "213JW7" e "217LVQ" id lto, 21 January, 2014 'sdate' January 9, 2014 edate, 10 January 2014 'mdate', 11 January 2014 medate double UNION ALL

    SELECT lfrom "215Y71", "217LVQ" lto, mi, "216TVZ" id "213JW7", 22 January, 2014 'sdate' January 23, 2014 edate, 24 January, 2014 'mdate' January 25, 2014 medate double UNION ALL

    SELECT '234IJF' lfrom, NULL, "234YU" e "3IUED" id lto, 26 January 2014 'sdate', 27 January 2014 edate, 28 January 2014 'mdate', 29 January 2014 medate OF double

    )

    some lines have parent/child relationship and some does not. for example, the first two query (data) are link together. online, the value of lto (215ZV9) corresponds to the id value

    in line 1.  the value of lfrom in row1 (213NY1) corresponds to the value of online id.

    the same scenario occurs in rows 3 and 4.  5th doesn't have any line which is a child. tier 5 is a single parent

    I want to WRITE a query that gives the following result.

    Mid id initial_date final_date

    =======================================

    215ZVD 215ZV9 1 January 2014 "January 5, 2014"

    "215ZVD 213NY1 7 January 2014" January 6, 2014 "

    "213JW7 217LVQ 21 January 2014 ' 11 January 2014"

    "213JW7 216TVZ 24 January 2014 ' 23 January 2014"

    "234YU 3IUED 26 January 2014 ' 27 January 2014"

    ONLY WHEN there is a parent/child relationship, initial DATE AND follow the final data WHAT such as

    FIRST date of deadline DATE

    < Mdate > < EDate > - for child

    < SDate > < MEDate > - for parent

    WHEN there is no relationship of parent/child (e.g. ONLY a parent ROW) THEN

    FIRST date of deadline DATE

    < SDate > < EDate-> parent

    can someone help me write a query for the above output

    with tt AS

    (SELECT a.*,

    ROW_NUMBER () ON LV (MIDDLE ORDER BY SDATE PARTITION),

    CASE

    WHEN ID = NVL (ADVANCE (lto, 1) OVER (PARTITION BY Middle ORDER BY sdate), LAG (lfrom) OVER (ORDER BY sdate Middle PARTITION))

    THEN 1

    END flg

    DATA one

    )

    SELECT THE MIDDLE,

    ID,

    CASE

    WHEN flg IS NOT NULL

    THEN

    CASE

    WHAT LV = 1

    THEN SDATE

    WHAT LV = 2

    THEN mDATE

    END

    Of ANOTHER sdate

    END INITIALDATE

    CASE

    WHEN flg IS NOT NULL

    THEN

    CASE

    WHAT LV = 1

    THEN mEDATE

    WHAT LV = 2

    THEN EDATE

    END

    Of ANOTHER edate

    END FINALDATE

    TT;

    Output:

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

    MID ID INITIALDATE FINALDATE

    213JW7 217LVQ 21 January 2014 January 11, 2014

    213JW7 216TVZ 24 January 2014 23 January 2014

    215ZVD 215ZV9 January 1, 2014 5 January 2014

    215ZVD 213NY1 January 7, 2014 6 January 2014

    234YU 3IUED 26 January 2014 January 27, 2014

  • Parent child query

    I got the exit for parent-child relationships

    Select
    LPAD (' ', 2 * level) | child
    Of
    prune_test
    Start by
    parent is null
    connect
    child precondition = parent

    as
    1
    -12
    -120
    -124
    -127
    -712
    -7122
    -7125
    -7127

    But I want like
    Parent child Child1 2 child3
    1
    1 12
    1 12 120
    1-12-124
    1-12-127
    1 12 712
    1 12 712 7122
    1 12 712 7125
    1 12 712 7127

    Can someone help me...
    Thank you
    Mani

    Published by: Mani on November 4, 2010 18:54

    Do you just need a sys link by road

    with prune_test as
    (select null parent, 1 child from dual union all
     select 1, 12 from dual union all
     select 12, 120 from dual union all
      select 12, 124 from dual union all
       select 12, 127 from dual union all
       select 12, 712 from dual union all
       select 712,71522 from dual union all
       select 712, 7125 from dual union all
       select 712, 7127 from dual
       )
    
    select
    lpad(' ', 2*level) || child, sys_connect_by_path(child,' ')
    from
    prune_test
    start with
    parent is null
    connect by
    prior child=parent 
    
    LPAD('',2*LEVEL)||CHILD     SYS_CONNECT_BY_PATH(CHILD,'')
      1           1
        12            1 12
          120      1 12 120
          124      1 12 124
          127      1 12 127
          712      1 12 712
            71522      1 12 712 71522
            7125      1 12 712 7125
            7127      1 12 712 7127
    
  • Parent - child relationship constraint Unique 5.0 apex oracle

    Oky so I will try to avoid duplicate values get inserted in the parent-child node.

    So basically when there's a node parent (Mobile) I can't create same node with the same name.

    Even for the child node, if there is a child node name there may be another named A.

    Structure:

    Mobile (parent) /Android (Child) /KitKat (subchild) (allowed)

    Mobile/apple/ios(Now allowed Same Parent name)

    Win7/Windows/win7(not allowed same child)

    So a big child and the parent must be unique at any time.

    77.JPG

    create an index of single "TEST_UK" on tablename (parent_id, upper (child_name));

    see this too for a case-insensitive unique constraint

    Case-insensitive unique constraint

  • Recursive SQL - Parent child

    Hello

    In a table, I had hierarchical data (parent, child), when the mother is a child of another parent.
    It is upto level4. (I mean child = > Parent1 = > Parent2 = > Grand Parent)

    Child = > Parent
    = A1 > B1
    A2 = > B1
    A3 = > B1
    B1 = > B2
    B2 = > B3
    B3 = > B4

    I need result like - each child has his parents and future parents

    As:
    Parent1 Parent2 Grand mother
    =========================

    = A1 > B1 - A1 first Parent
    A1 = > b2--deuxieme Parent of A1
    A1 = > b3--troisieme Parent of A1
    A1 = > B4 - grandparent


    Help, please. Is this possible with you connect function? I am tired of using it but I get only parents for each.

    Thank you
    Bobin

    Hi, Blanchette,

    To repeat a certain value in the first row on all connected on lines, use CONNECT_BY_ROOT

    SELECT     CONNECT_BY_ROOT child   AS starting_point
    ,     parent
    FROM     table_x
    START WITH     child     = 'A1'     -- or whatever
    CONNECT BY     chilD     = PRIOR parent;
    
  • How to perform account on a Table hierarchical Oracle based on the Parent link

    Hello


    I have the following to Oracle 11 g R2 hierarchical table definition:


    Table Name: TECH_VALUES:
      ID,
      GROUP_ID,
      LINK_ID
      PARENT_GROUP_ID,
      TECH_TYPE

    Above the hierarchical table definition, some examples of data might look like this:


    ID      GROUP_ID      LINK_ID      PARENT_GROUP_ID      TECH_TYPE 
    ------- ------------- ------------ -------------------- --------------
    1       100           LETTER_A     0
    2       200           LETTER_B     0
    3       300           LETTER_C     0
    4       400           LETTER_A1    100                  A 
    5       500           LETTER_A2    100                  A 
    6       600           LETTER_A3    100                  A 
    7       700           LETTER_AA1   400                  B 
    8       800           LETTER_AAA1  700                  C 
    9       900           LETTER_B2    200                  B 
    10      1000          LETTER_BB5   900                  B 
    12      1200          LETTER_CC1   300                  C
    13      1300          LETTER_CC2   300                  C
    14      1400          LETTER_CC3   300                  A
    15      1500          LETTER_CCC5  1400                 A
    16      1600          LETTER_CCC6  1500                 C
    17      1700          LETTER_BBB8  900                  B
    18      1800          LETTER_B     0
    19      1900          LETTER_B2    1800                 B 
    20      2000          LETTER_BB5   1900                 B 
    21      2100          LETTER_BBB8  1900
                     B


    Keeping in mind that there are only three Types of technology, i.e. A, B and C, but could not span on different LINK_IDs , how can I do a count on these three different TECH_TYPEs based solely on the ID of parent link where the parent group id is 0 and there are children below them?

    NOTE: It is also possible to have parents in dual link ID such as LETTER_B and all values of children but different group ID.

    I'm basically after a table/report query that looks like this:

    Link ID        Tech Type A         Tech Type B          Tech Type C
    -------------- ------------------- -------------------- -------------------
    LETTER_A      
    3                   1                    1
    LETTER_B      
    0                   3                    0
    LETTER_C      
    2                   0                    3
    LETTER_B      
    0                   3                    0

    Be hierarchical and my table can consist more of 30 000 files, I must also ensure that performance to produce the report above shown here query is fast.

    Obviously, in order to produce the report above, I need to gather all necessary County outages based on TECH_TYPE for all parents of the link id where the PARENT_GROUP_ID = 0 and store it in a table according to the guidelines of this report layout.

    Hope someone can help with maybe a combined query that performs the counties as well as stores the information in a new table called LINK_COUNTS, which will be based on this report. Columns of this table will be:

    ID,

    LINK_ID,

    TECH_TYPE_A,

    TECH_TYPE_B,

    TECH_TYPE_C

    At the end of this entire requirement, I want to be able to update the LINK_COUNTS table based on the results returned by the sample data above in a SQL UPDATE transaction as the link ID parent top-level already exists within my table LINK_COUNTS, just need to provide values for breaking County for each parent node link , i.e.

    LETTER_A

    LETTER_B

    LETTER_C

    LETTER_B

    using something like:

    UPDATE link_counts

    SET (TECH_TYPE_A,TECH_TYPE_B,TECH_TYPE_C) =

       (with xyz  where link_id = LINK_COUNTS.link_id .... etc

    Which must match exactly the above table/report

    Thank you.

    Tony.

    Hi, John,.

    Thanks for posting the sample data.

    John Spencer wrote:

    ...  If you need to hide the ID column, then you could simply encapsulate another external query around me. ...

    Or simply not display the id column:

    Select link_id, -id,

    Count (case when tech_type = 'A' end then 1) tech_a.

    Count (case when tech_type = 'B' then 1 end) tech_b,.

    Count (case when tech_type = "C" then 1 end) tech_c

    of (connect_by_root select link_id link_id,)

    the connect_by_root ID, tech_type

    of sample_data

    Start with parent_group_id = 0

    connect prior group_id = parent_group_id)

    Link_id group, id

    order by link_id, id;

    Same results, using SELECT... PIVOT

    WITH got_roots AS

    (

    SELECT CONNECT_BY_ROOT link_id AS link_id

    Id CONNECT_BY_ROOT ID

    tech_type

    OF sample_data

    START WITH parent_group_id = 0

    CONNECT BY PRIOR group_id = parent_group_id

    )

    SELECT link_id, tech_a, tech_b, tech_c

    OF got_roots

    PIVOT (COUNT (*)

    FOR tech_type IN ('A' AS tech_a

    'B' AS tech_b

    'C' AS tech_c

    )

    )

    Id ORDER BY link_id

    ;

  • Sum of a stand-alone parent-child table

    I have two tables - a 'key' table containing a parent-child relationship of multi-layer and a table 'amount' that contains the keys for the nodes in the key as well as table of numeric values (for example the amounts).
    I want a query that returns each line in the table of key as well as the sum of the amount amounts of the table for the set of nodes of this key (so the root node would be the sum of all values of quantity).

    Here's what I mean: I have two tables, the KEY and the AMOUNT

    KEY has two columns, keys, and parent_key; key and parent_key have a relationship CONNECT BY parent_key = prior key (with null for the root parent_key):
    KEY     PARENT_KEY
    0       null
    1       0
    2       0
    3       0
    1A      1
    2A      2
    2B      2
    3A      3
    3B      3
    3C      3
    1A1     1A
    1A2     1A
    2A1     2A
    2A2     2A
    2B1     2B
    3A1     3A
    3A2     3A
    3C1     3C
    3C2     3C
    AMOUNT a two columns, keys, and amount; key points to KEY.key and amount is a value for that particular key
    (Note that all key values are leaf nodes in the KEY table)
    KEY     AMOUNT
    1A1     1 
    1A2     2 
    2A1     3 
    2A2     4 
    2B1     5 
    3A1     6 
    3A2     7 
    3C1     8 
    3C2     9 
    What I want is a result that looks like this, where the amount of each key is the sum of the amounts of its possible keys sheet
    KEY     AMOUNT
    0       45
    1        3
    2       12
    3       30
    1A       3
    2A       7
    2B       5
    3A      13
    3B       0
    3C      17
    1A1      1
    1A2      2
    2A1      3
    2A2      4
    2B1      5
    3A1      6
    3A2      7
    3C1      8
    3C2      9
    For example, the value of the key 2 a, 7, is the sum of the values of 2 a 1 and a 2, 2; key value of 3 is the sum of 3 a 1, a 3, 2, 3, C 1 and 2 of 3.

    Is it possible to do this with a single query?
    The idea I came with is, do a select on the KEY with a "Key CONNECT_BY_PATH" column so that each line contains a string that contains the keys of all his ancestors and then do a join on AMOUNT with IN the CONNECT_BY_PATH amount.key column; However, with a large amount of data, it takes a little time. Is there a way faster / more obvious to achieve?

    OK you have almost everything you need. Outer join just your two tables, and then perform a hierarchical query, noting the key root of each tree. Then group the data set resulting:

    with t1 as (select '0' "KEY", '' parent_key from dual
      union all select '1', '0' from dual
      union all select '2', '0' from dual
      union all select '3', '0' from dual
      union all select '1A', '1' from dual
      union all select '2A', '2' from dual
      union all select '2B', '2' from dual
      union all select '3A', '3' from dual
      union all select '3B', '3' from dual
      union all select '3C', '3' from dual
      union all select '1A1', '1A' from dual
      union all select '1A2', '1A' from dual
      union all select '2A1', '2A' from dual
      union all select '2A2', '2A' from dual
      union all select '2B1', '2B' from dual
      union all select '3A1', '3A' from dual
      union all select '3A2', '3A' from dual
      union all select '3C1', '3C' from dual
      union all select '3C2', '3C' from dual
    ), t2 as (select '1A1' "KEY", 1 amount from dual
      union all select '1A2', 2 from dual
      union all select '2A1', 3 from dual
      union all select '2A2', 4 from dual
      union all select '2B1', 5 from dual
      union all select '3A1', 6 from dual
      union all select '3A2', 7 from dual
      union all select '3C1', 8 from dual
      union all select '3C2', 9 from dual
    ), t3 as (
      select t1.key, parent_key, amount
        from t1 left join t2 on t1.key = t2.key
    ), t4 as (
      select CONNECT_BY_ROOT key root_key
           , level lv
           , t3.*
        from t3
        connect by prior t3.key = parent_key
    )
    select root_key "KEY", sum(amount) amount
      from t4
     group by root_key
     order by length(root_key), root_key;
    
  • Blockages with parent/child tables

    Guys,

    We have a parent-child of tables in our database with the DDL below:

    CREATE TABLE 'ACCOUNT '.

    (SELECT 'ACCOUNT_ID' VARCHAR2 (32 BYTE) NOT NULL,)

    X, Y, Z,...),

    'XPK_ACCOUNT' CONSTRAINT PRIMARY KEY ('ACCOUNT_ID');

    CREATE TABLE ACCOUNT_PARTITION ".

    (SELECT 'ACCOUNT_ID' VARCHAR2 (32 BYTE) ENABLE NOT NULL, "BALANCE" NUMBER (5.0) NOT NULL,)

    X, Y, Z,...),

    'XPK_ACCOUNT_PARTITION' CONSTRAINT PRIMARY KEY ('ID_COMPTE', 'BALANCE')

    KEY FOREIGN CONSTRAINT 'ACCOUNT_PARTITION_FK1' ('ACCOUNT_ID')

    SELECT THE 'ACCOUNT' ('ACCOUNT_ID') REFERENCES);

    "Lately, we cross " ""ORA-00060: Deadlock detected while you wait for resources ' errors while DELETING in the tables above. Please note that the tables of the child is not any clue except KP index.


    Could someone please suggest resolution for us to minimize the error of blocking?


    Respect,

    Bugs

    Imagine you remove account, Oracle must verify there is no record of the child in ACCOUNT_PARTITION, this is because as your FK is restrict the deletions (do not allow the removal if there are child records).  As ACCOUNT_PARTITION. Account_id is indexed so it will be an exclusive table lock to find this, locks the table.

    Another way of thinking is, imagine that you have performed the following query without and ACCOUNT_ID index:

    Select *.

    of ACCOUNT_PARTITION

    where ACCOUNT_ID =

    He SHOULD do a full table scan right?  Well well, even on a deletion of the parent. It attempts to identify lines for the purpose of blocking,

    As a general rule, it is always a good idea to index FKs.

  • parent/child relationship hirarchy

    Hi everyone, consider the sample data

    SELECT LFROM '1TR1Y6', NULL LTO, MID '11ZFDD', '21XHK7' double UNION ALL TID-

    SELECT '1TR1YF' LFROM, LTO NULL, '11ZFDD' MI '21XHK5' TID FROM dual UNION ALL-

    SELECT '1TR1X1' LFROM, LTO NULL, '11ZFDD' MI '21XHK8' TID FROM dual UNION ALL-

    SELECT '1LSZX1' LFROM, LTO NULL, '11ZFDD' MI '1TR1YD' TID FROM dual UNION ALL-

    SELECT LFROM "1LSZWQ", "21XHK7" LTO, MID '11ZFDD', '1TR1Y6' TID FROM dual UNION ALL-

    SELECT LFROM "1LSZX2", "21XHK5" LTO, MID '11ZFDD', '1TR1YF' TID FROM dual UNION ALL-

    SELECT LFROM "1LSZVG", "21XHK8" LTO, MID '11ZFDD', '1TR1X1' TID FROM dual UNION ALL-

    SELECT LFROM "4LSSVG", "21XHK9" LTO "11AAA' MI '1TR1X1' TID double UNION ALL

    SELECT "AAAAA" LFROM, LTO NULL, '11ABB' e, 'CCCCCC' double UNION ALL TID

    SELECT "BATH" LFROM, 'CCCCCC' LTO, MID '11ABB', 'AAAAA' double UNION ALL TID

    some of them have a parent/child releationship. for example, let take rank with LFROM = 1TR1Y6

    1TR1Y6 (lfrom) corresponds to the fifth line with TID 1TR1Y6.  TID 1TR1Y6 LTO COLUMN value corresponds to the first line TID (21XHK7)

    It before these two LINES are IN a parent/child relationship.

    lets take another example.  LINE two WITH LFROM = 1TR1YF matches sixth RANK WITH TID 1TR1YF.  the sixth LINE LTO COLUMN (21XHK5) corresponds to the SECOND TID of LINE.

    Once again the parent child relationship. There are two lines that do not have the relationship of parent/child (ex.  line 8)

    Im trying to write a query that can partition the data in the middle column and find the parent/child relationship. the output of the above data should be

    LTO LFROM MIDDLE TID FLAG

    1TR1Y6 NULL 11ZFDD 21XHK7 1

    1LSZWQ 21XHK7 11ZFDD 1TR1Y6 1

    1TR1YF NULL 11ZFDD 21XHK5 1

    1LSZX2 21XHK5 11ZFDD 1TR1YF 1

    1TR1X1 NULL 11ZFDD 21XHK8 1

    1LSZVG 21XHK8 11ZFDD 1TR1X1 1

    1LSZX1 NULL 11ZFDD 1TR1YD 0

    4LSSVG 21XHK9 11AAA 1TR1X1 0

    ABDELKÉBIR 11ABB CCCCCC NULL 1

    CCCCCC 11ABB AAAAA BATH 1

    For simplicity, I posted the release with parent/child, side by side in the sequence.  the order does not matter as long as the flag column (pull the column) is set to an appropriate value (1 if parent/child, 0 no parent/child)

    the flag column value is derived from column to indicate the parent/child relationship was found.

    I try using lead, the lag function but I have problem of sorting data from parent and child line could come at random order (they are not side by side).

    It is therefore difficult to use lead because you don't know how many lines to carry forward.

    can someone help me write a query that displays the output above

    SELECT T1. LFROM,

    T1. LTO,

    T1. ENVIRONMENT,

    T1. TID,

    (

    SELECT COUNT (*)

    OF TBL T2

    WHERE)

    T2. TID = T1. LFROM

    OR

    T2. LFROM = T1. TID

    )

    AND T2. MI = T1. MID

    ) FLAG

    OF TBL T1

    /

    LTO LFROM MIDDLE TID FLAG
    ------ ------ ------ ------ ----------
    1LSZWQ 21XHK7 11ZFDD 1TR1Y6 1
    1LSZX2 21XHK5 11ZFDD 1TR1YF 1
    1LSZVG 21XHK8 11ZFDD 1TR1X1 1
    CCCCCC 11ABB AAAAA BATH 1
    1TR1X1 11ZFDD 21XHK8 1
    1TR1X1 11ZFDD 21XHK8 1
    1LSZX1 11ZFDD 1TR1YD 0
    1TR1Y6 11ZFDD 21XHK7 1
    ABDELKÉBIR 11ABB CCCCCC 1
    1TR1YF 11ZFDD 21XHK5 1
    4LSSVG 21XHK9 11AAA 1TR1X1 0

    11 selected lines.

    SQL >

    SY.

  • query rewite enable cube + jump level hierarchy problem

    Hello

    can someone help me on the following scenario, please?

    (I use OWB 11.2 client on WIN XP)

    I just created a dimension, i.e. dim_1 with three levels (l1, l2 and l3) with the ' ROLAP: with Cube MV ' storage option. the business identifier is of type number named 'key '. The standard hierarchy of the dimension is
    by default except that I have defined L1 level as him "jump at the level" of the L3 level. As I'd hoped associates the modified dimension table so that the key added to level L3 as his parents another level L1.

    Then I designed a map of ETL to load the following values:
    Hierarchy (Default): L1-L2-L3 > >
    Keychain attr. : 1-> 2-> 3
    and
    hierarchy (using hierarchical): L1-L3 >
    Keychain attr. : 1 > 4



    This means that the '1' L1 button is parent of key '3' or '4' of L3.
    Then I created a single dimension cube with the "ROLAP: with the Cube of MV" storage option. The only measure of the cube is named "N" of type number. The level of the dimension of the cube is L3 as a default value. Then I designed a mapping of ETL to load following values in this measure:
    « N » - « L3 ». "" Key.
    __________________
    1 - 3
    2 - 4

    When I update the related materialized view of the cube it does return no rows.

    * 1. why what is happening? *

    But when firstly, I refresh the MV associated with the dimension, and then refresh the cube MV, it returns the following incorrect result:
    Level.Key - N - County
    ___________________________
    L2.2 - 2-1
    L1.1 - 2-1

    The correct result should be:

    Level.Key - N - County
    ___________________________
    L2.2 - 1-1
    L1.1 - 3-2

    * 2. why what is happening? *

    When I got Disabling query rewrite of the cube, then there is no need to be refreshed dimension MV first. Refreshing Cube MV returns the following results about:

    Level.Key - N - County
    ___________________________
    L2.2 - 1-1
    L1.1 - 3-2
    L2. -2-1

    * 3.Is it bound to the ENABLE QUERY REWRITE of cube MV property? *

    Thanks in advance,

    SMSK.

    Command is not supported in cube MVs, see the documentation for OLAP;
    http://docs.Oracle.com/CD/E11882_01/OLAP.112/e17123/cubes.htm#CHDHBGGB

    A cube must conform to these requirements, before it can be referred to as a cube materialized view:
    * All the dimensions of the cube have at least a level and a level-based hierarchy. Ragged and non-hierarchical hierarchies are not supported. The dimensions should be mapped.
    * All dimensions in the cube using the same aggregation operator, which is SUM, MIN, or MAX.
    * The cube has one or more dimensions and one or more measures.
    * The cube is fully defined and mapped. For example, if the cube has five steps, then all five are mapped to the source tables.
    * The data for the cube type is NUMBER, VARCHAR2, NVARCHAR2, or DATE.
    * Source detail tables support dimension and count constraints. If they have not been defined, then use the Advisor to relational schema to generate a script that defines on detail charts.
    * The cube is compressed.
    * The cube can be accompanied by calculated measures, but he can not support analytics more advanced in the cube script.

    See you soon
    David

Maybe you are looking for