Requirement with hierarchical query results

I've a table contains the following columns and the data
create table test_test2 (do_id_tp varchar2(32),do_id number ,do_up_tp varchar2(32),do_up_id number)
insert into test_test2 values('A_S',100170,'A_S',100001);
insert into test_test2 values('P_G',1001052,'P_G',100001);
insert into test_test2 values('A_S',1001054,'P_G',100001);
insert into test_test2 values('A_S',1001055,'P_G',100001);
insert into test_test2 values('P_G',1001037,'P_G',100001);
insert into test_test2 values('P_G',1001038,'P_G',100001);
insert into test_test2 values('A_S',1001053,'P_G',100001);
insert into test_test2 values('A_S',1001056,'P_G',100001);
insert into test_test2 values('A_S',1001052,'P_G',100001);
insert into test_test2 values('A_S',1001051,'P_G',100001);
insert into test_test2 values('P_G',100001,'R_S',100001);
insert into test_test2 values('P_G',1001031,'R_S',100001);
insert into test_test2 values('P_G',1001035,'R_S',100001);
insert into test_test2 values('A_S',100170,'P_G',100001);
insert into test_test2 values('A_S',1001054,'A_S',100001);
insert into test_test2 values('A_S',1001055,'A_S',100001);
insert into test_test2 values('A_S',1001053,'A_S',100001);
insert into test_test2 values('A_S',1001056,'A_S',100001);
insert into test_test2 values('A_S',1001051,'A_S',100001);
insert into test_test2 values('A_S',1001052,'A_S',100001);
insert into test_test2 values('A_S',100001,'P_G',100001);In the above data R_S is at high level (Means P_G and A_S should depend on R_S)
similarly P_G is next level ( A_S should depend on P_G OR P_G depends on P_G)
the lower level is A_S ( A_S depends on A_S)
So i tried the following query which gives the child list of a parent
SELECT  DO_UP_TP,DO_UP_ID ,do_id_tp,wm_concat( CONNECT_BY_ROOT  do_id) 
                                FROM test_test2
                                where do_up_id=100001
                                   CONNECT BY  nocycle PRIOR do_up_id = do_id
                                   group  by  DO_UP_TP,DO_UP_ID ,do_id_tp;The requirement is for each do_up_id ( i'll get a list of do_id (which are in wm_concat).).
i've to check in flag column in Following table
create table check_test2 (d_id ) as
select do_up_id from test_test2 union
select do_id from test_test2   
alter table check_test2 add (flag char(1) DEFAULT 'N')For Ex: R_S (100001) has the childs P_G(100001),P_G(1001031),P_G(1001035) {This is a branch in a Tree}
Now first i've to check R_S(100001) is active or not in the check_test2 table, If 'N' then check it's child's flag until it finds no more childs.
If no child is having 'Y' then mark the entire branch as 'N'
This i've to do for all the do_up_id in TEST_TEST2 table.
I tried the following package plz correct me as per requirement
CREATE OR REPLACE package USPF_APR.test_pak1 as
FUNCTION map_object ( obj_typ_in VARCHAR2 ) RETURN VARCHAR2;
  CURSOR c_c1
    IS
     select * from test_test2 where (do_id in (100001) or do_up_id in (100001));
    TYPE test_ttyp IS TABLE OF c_c1%ROWTYPE INDEX BY PLS_INTEGER;
procedure search_obj(obj_type varchar2);
end;
CREATE OR REPLACE package body USPF_APR.test_pak1 as
FUNCTION map_object ( obj_typ_in VARCHAR2 ) RETURN VARCHAR2
     IS
  begin
       dbms_output.put_line ('Hello');
  return 'abc';
end;
PROCEDURE search_obj (obj_type VARCHAR2)
   IS
      test_tab   test_ttyp;
      test_tab_r   c_c1%ROWTYPE;
      dep_up_id NUMBER;
      dep_id NUMBER;
      con_dep_up_id VARCHAR2(2100);
      con_dep_id VARCHAR2(2100);
   BEGIN
      OPEN c_c1;
        LOOP
             Fetch c_c1 into test_tab_r;
             exit when c_c1%NOTFOUND;
             test_tab(test_tab.COUNT + 1) := test_tab_r;
         END LOOP;
        CLOSE c_c1;  
              DBMS_OUTPUT.put_line ('Test_tab.count is ...'|| test_tab.COUNT);
        FOR i IN 1 .. test_tab.COUNT LOOP
                               WITH T AS
                      ( SELECT test_tab(i).do_id   , test_tab(i).do_up_id
                          FROM DUAL)
                           SELECT test_tab(i).do_up_id ,wm_concat( CONNECT_BY_ROOT test_tab(i).do_id)  INTO dep_up_id ,dep_id
                                FROM T
                                CONNECT BY  nocycle PRIOR test_tab(i).do_up_id=test_tab(i).do_id
                                   group  by test_tab(i).do_up_id;
                                 con_dep_id := con_dep_id || ',' || dep_id;                         
                  DBMS_OUTPUT.put_line ('Value of dep_id'||con_dep_id );
       END LOOP;
        DBMS_OUTPUT.put_line ('.....****************************...');
         ----   Here need to compare with check_test2 table  for the active ness of the id  in where condition i've to pass the con_dep_id
         ---    But how to differentiate  For which parent the child is checking the childs
         --   The invalid records( where  for ex:do_up_id =100001 ) should be removed form test_tab   Or the valid records can be copied to another associative array having the same structure as test_tab
    END;
   END;
EXEC TEST_PAK1.search_obj ('Hi');
I even confused with
SELECT test_tab(i).do_up_id ,wm_concat( CONNECT_BY_ROOT test_tab(i).do_id)  INTO dep_up_id ,dep_id
because wm_concat gives me ' , ' sepearated values where they can't fit into dep_id variablecreating global temporary tables will be useful or not !!!
Plz help me
Edited by: smile on Jan 5, 2012 10:23 PM

I've a table contains the following columns and the data
create table test_test2 (do_id_tp varchar2(32),do_id number ,do_up_tp varchar2(32),do_up_id number)
insert into test_test2 values('A_S',100170,'A_S',100001);
insert into test_test2 values('P_G',1001052,'P_G',100001);
insert into test_test2 values('A_S',1001054,'P_G',100001);
insert into test_test2 values('A_S',1001055,'P_G',100001);
insert into test_test2 values('P_G',1001037,'P_G',100001);
insert into test_test2 values('P_G',1001038,'P_G',100001);
insert into test_test2 values('A_S',1001053,'P_G',100001);
insert into test_test2 values('A_S',1001056,'P_G',100001);
insert into test_test2 values('A_S',1001052,'P_G',100001);
insert into test_test2 values('A_S',1001051,'P_G',100001);
insert into test_test2 values('P_G',100001,'R_S',100001);
insert into test_test2 values('P_G',1001031,'R_S',100001);
insert into test_test2 values('P_G',1001035,'R_S',100001);
insert into test_test2 values('A_S',100170,'P_G',100001);
insert into test_test2 values('A_S',1001054,'A_S',100001);
insert into test_test2 values('A_S',1001055,'A_S',100001);
insert into test_test2 values('A_S',1001053,'A_S',100001);
insert into test_test2 values('A_S',1001056,'A_S',100001);
insert into test_test2 values('A_S',1001051,'A_S',100001);
insert into test_test2 values('A_S',1001052,'A_S',100001);
insert into test_test2 values('A_S',100001,'P_G',100001);In the above data R_S is at high level (Means P_G and A_S should depend on R_S)
similarly P_G is next level ( A_S should depend on P_G OR P_G depends on P_G)
the lower level is A_S ( A_S depends on A_S)
So i tried the following query which gives the child list of a parent
SELECT  DO_UP_TP,DO_UP_ID ,do_id_tp,wm_concat( CONNECT_BY_ROOT  do_id) 
                                FROM test_test2
                                where do_up_id=100001
                                   CONNECT BY  nocycle PRIOR do_up_id = do_id
                                   group  by  DO_UP_TP,DO_UP_ID ,do_id_tp;The requirement is for each do_up_id ( i'll get a list of do_id (which are in wm_concat).).
i've to check in flag column in Following table
create table check_test2 (d_id ) as
select do_up_id from test_test2 union
select do_id from test_test2   
alter table check_test2 add (flag char(1) DEFAULT 'N')For Ex: R_S (100001) has the childs P_G(100001),P_G(1001031),P_G(1001035) {This is a branch in a Tree}
Now first i've to check R_S(100001) is active or not in the check_test2 table, If 'N' then check it's child's flag until it finds no more childs.
If no child is having 'Y' then mark the entire branch as 'N'
This i've to do for all the do_up_id in TEST_TEST2 table.
I tried the following package plz correct me as per requirement
CREATE OR REPLACE package USPF_APR.test_pak1 as
FUNCTION map_object ( obj_typ_in VARCHAR2 ) RETURN VARCHAR2;
  CURSOR c_c1
    IS
     select * from test_test2 where (do_id in (100001) or do_up_id in (100001));
    TYPE test_ttyp IS TABLE OF c_c1%ROWTYPE INDEX BY PLS_INTEGER;
procedure search_obj(obj_type varchar2);
end;
CREATE OR REPLACE package body USPF_APR.test_pak1 as
FUNCTION map_object ( obj_typ_in VARCHAR2 ) RETURN VARCHAR2
     IS
  begin
       dbms_output.put_line ('Hello');
  return 'abc';
end;
PROCEDURE search_obj (obj_type VARCHAR2)
   IS
      test_tab   test_ttyp;
      test_tab_r   c_c1%ROWTYPE;
      dep_up_id NUMBER;
      dep_id NUMBER;
      con_dep_up_id VARCHAR2(2100);
      con_dep_id VARCHAR2(2100);
   BEGIN
      OPEN c_c1;
        LOOP
             Fetch c_c1 into test_tab_r;
             exit when c_c1%NOTFOUND;
             test_tab(test_tab.COUNT + 1) := test_tab_r;
         END LOOP;
        CLOSE c_c1;  
              DBMS_OUTPUT.put_line ('Test_tab.count is ...'|| test_tab.COUNT);
        FOR i IN 1 .. test_tab.COUNT LOOP
                               WITH T AS
                      ( SELECT test_tab(i).do_id   , test_tab(i).do_up_id
                          FROM DUAL)
                           SELECT test_tab(i).do_up_id ,wm_concat( CONNECT_BY_ROOT test_tab(i).do_id)  INTO dep_up_id ,dep_id
                                FROM T
                                CONNECT BY  nocycle PRIOR test_tab(i).do_up_id=test_tab(i).do_id
                                   group  by test_tab(i).do_up_id;
                                 con_dep_id := con_dep_id || ',' || dep_id;                         
                  DBMS_OUTPUT.put_line ('Value of dep_id'||con_dep_id );
       END LOOP;
        DBMS_OUTPUT.put_line ('.....****************************...');
         ----   Here need to compare with check_test2 table  for the active ness of the id  in where condition i've to pass the con_dep_id
         ---    But how to differentiate  For which parent the child is checking the childs
         --   The invalid records( where  for ex:do_up_id =100001 ) should be removed form test_tab   Or the valid records can be copied to another associative array having the same structure as test_tab
    END;
   END;
EXEC TEST_PAK1.search_obj ('Hi');
I even confused with
SELECT test_tab(i).do_up_id ,wm_concat( CONNECT_BY_ROOT test_tab(i).do_id)  INTO dep_up_id ,dep_id
because wm_concat gives me ' , ' sepearated values where they can't fit into dep_id variablecreating global temporary tables will be useful or not !!!
Plz help me
Edited by: smile on Jan 5, 2012 10:23 PM

Similar Messages

  • Need to populate a hierarchical query results in detail block of WIPTXCFM

    Hi All,
    I would need to customize WIPTXCFM to populate all layered sub assembly schedule numbers against a Final Assembly schedule number.
    Requirement is as soon as User enter a FA schedule number; it should populate all levels Sub Assembly Schedule Numbers under this.
    I have thought of 1 approach; need suggestion if there is any better way to achieve this to improve the performance.
    My Approach: In custom WIPTXCFM form once the FA schedule number is entered; I can fetch all below level data(e.g Level1, level2 ...etc.)
    using a cursor with hierarchical query. Then loop through the cursor and insert them in the block after the FA record.
    So would look for your suggestion if there is any other better way to achieve this.
    Thanks in adv.
    Regards.

    880860 wrote:
    Hi All,
    I would need to customize WIPTXCFM to populate all layered sub assembly schedule numbers against a Final Assembly schedule number.
    Requirement is as soon as User enter a FA schedule number; it should populate all levels Sub Assembly Schedule Numbers under this.
    I have thought of 1 approach; need suggestion if there is any better way to achieve this to improve the performance.
    My Approach: In custom WIPTXCFM form once the FA schedule no is entered; I can fetch all below level data(e.g Level1, level2 ...etc.)
    using a cursor with hierarchical query. Then loop through the cursor and insert them in the block after the FA record.
    As per my findings; this hierarchical query takes longer to fetch the below levels data, around 1.5 mins.
    Hello 880860,
    If your are talking about EBS customization you can post at {forum:id=475}.
    Hope this helps

  • Problem with Hierarchical query

    Gurus,
    I have a problem with hierarchical query, which I am pasting below.
    select sys_connect_by_path (Fname,'/')"PATH",Fname,id,level
    ,(SELECT COUNT(ID)-1 FROM (SELECT CONNECT_BY_ROOT LNAME LNAME,ID FROM CMT_PERSON
    START WITH ID = 'emplo000000000126009'
    CONNECT BY PRIOR ID=MANAGER_ID)
    GROUP BY FNAME)"COUNT"
    from CMT_PERSON
    WHERE
    LEVEL <= 4
    ----And ID='emplo000000000001877'
    CONNECT BY PRIOR id=manager_id
    ----AND NOT LEVEL > 3
    START WITH ID='emplo000000000126009'
    As per the result, count is getting repeated for all the levels. That is, count is coming 16100 for every level, Can you please help where exactly I am going wrong
    Regards

    You do not say anything about what count you want to get?
    A wild guess could be:
    select
       sys_connect_by_path (p1.fname, '/') "PATH",
       p1.fname,
       p1.id,
       level,
       (select count (id) - 1
        from
           (select connect_by_root p2.lname lname, p2.id
            from cmt_person p2
            start with p2.id = p1.id
            connect by prior p2.id = p2.manager_id)
        ) "COUNT"
    from cmt_person p1
    where level <= 4
    connect by prior p1.id = p1.manager_id
    start with p1.id = 'emplo000000000126009';Since your inner query simply starts with the hardcoded employee id, naturally it will give you the same count.
    My guess is your inner query should start with the person id from the outer query?
    If that is not the case - please state in plain english what you are trying to accomplish ;-)
    (Oh, and please paste code within tags so we can read it more easily...)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • How create HTML-list with hierarchical query?

    Hello all!
    I have table HIE (name,id,par) with hierarchical structure (par=id)
    As sample:
    select name
    FROM hie
    CONNECT BY PRIOR id=par
    START WITH par=0
    Root
    Branch 1
    Lief 11
    Lief 12
    Bracnh 2
    I need to create html-list from this table.
    How can I select from that table the structured output with TAGs "UL" "LI":
    <ul><li>root
    <ul>
    <li>branch 1
    <ul>
    <li>lief11</li>
    <li>lief12</li>
    </ul>
    </li></ul>
    <ul>
    <li>branch 2</li></ul>
    </li></ul>
    Sql-Guru, please, help!
    Message was edited by:
    natalia.demidchick
    Message was edited by:
    natalia.demidchick
    Message was edited by:
    natalia.demidchick
    Message was edited by:
    natalia.demidchick
    Message was edited by:
    natalia.demidchick

    Yes there was a mistake
    Try this. It should be good
    Processing ...
    CREATE TABLE TAB_A AS (
         SELECT 'ROOT' AS NAME,1 AS ID,NULL AS PARENT FROM DUAL
         UNION ALL
         SELECT 'BRANCH1' AS NAME,2 AS ID,1 AS PARENT FROM DUAL
         UNION ALL
         SELECT 'BRANCH2' AS NAME,3 AS ID,2 AS PARENT FROM DUAL
         UNION ALL
         SELECT 'LIEF1' AS NAME,4 AS ID,2 AS PARENT FROM DUAL
         UNION ALL
         SELECT 'LIEF2' AS NAME,5 AS ID,2 AS PARENT FROM DUAL
         UNION ALL
         SELECT 'BRANCH3' AS NAME,6 AS ID,1 AS PARENT FROM DUAL
         UNION ALL
         SELECT 'LIEF3' AS NAME,7 AS ID,2 AS PARENT FROM DUAL
         UNION ALL
         SELECT 'BRANCH5' AS NAME,8 AS ID,1 AS PARENT FROM DUAL
         UNION ALL
         SELECT 'LIEF4' AS NAME,9 AS ID,8 AS PARENT FROM DUAL
         UNION ALL
         SELECT 'LIEF5' AS NAME,10 AS ID,3 AS PARENT FROM DUAL
         UNION ALL
         SELECT 'LIEF6' AS NAME,11 AS ID,3 AS PARENT FROM DUAL
    Processing ...
    SELECT *
    FROM TAB_A
    Query finished, retrieving results...
       NAME                      ID                                   PARENT                
    ROOT                                            1                                       
    BRANCH1                                         2                                      1
    BRANCH2                                         3                                      2
    LIEF1                                           4                                      2
    LIEF2                                           5                                      2
    BRANCH3                                         6                                      1
    LIEF3                                           7                                      2
    BRANCH5                                         8                                      1
    LIEF4                                           9                                      8
    LIEF5                                          10                                      3
    LIEF6                                          11                                      3
    11 row(s) retrieved
    Processing ...
    CREATE GLOBAL TEMPORARY TABLE TEMP_TAB AS (
         SELECT LEVEL AS LV,ROWNUM AS RN,A.*
         FROM TAB_A A
         WHERE (1=0)
         START WITH PARENT IS NULL
         CONNECT BY PRIOR ID = PARENT
    Processing ...
    INSERT INTO TEMP_TAB
         SELECT LEVEL AS LV,ROWNUM AS RN,A.*
         FROM TAB_A A
         START WITH PARENT IS NULL
         CONNECT BY PRIOR ID = PARENT
    11 row(s) inserted
    Processing ...
    SELECT *
    FROM TEMP_TAB
    Query finished, retrieving results...
                      LV                                     RN                      NAME                      ID                                   PARENT                
                                         1                                      1 ROOT                                            1                                       
                                         2                                      2 BRANCH1                                         2                                      1
                                         3                                      3 BRANCH2                                         3                                      2
                                         4                                      4 LIEF5                                          10                                      3
                                         4                                      5 LIEF6                                          11                                      3
                                         3                                      6 LIEF1                                           4                                      2
                                         3                                      7 LIEF2                                           5                                      2
                                         3                                      8 LIEF3                                           7                                      2
                                         2                                      9 BRANCH3                                         6                                      1
                                         2                                     10 BRANCH5                                         8                                      1
                                         3                                     11 LIEF4                                           9                                      8
    11 row(s) retrieved
    Processing ...
    SELECT --LV,RN,1+(NVL(LAG(LV) OVER ( ORDER BY RN ASC),0)-LV+1) step,
         --lead(LV) OVER ( ORDER BY RN ASC NULLS LAST) next_lev,
         decode (lv-1,nvl(LAG(LV) OVER ( ORDER BY RN ASC),0),'<UL>','')||
         '<LI>'||NAME||'</LI>'||
         replace(
         RPAD(chr(10),1+(lv-NVL(lead(LV) OVER ( ORDER BY RN ASC),0))*5,'</UL>'),
         chr(10),
         ) AS HTML
    FROM TEMP_TAB A
    ORDER BY RN ASC
    Query finished, retrieving results...
                                          HTML                                      
    <UL><LI>ROOT</LI>                                                               
    <UL><LI>BRANCH1</LI>                                                            
    <UL><LI>BRANCH2</LI>                                                            
    <UL><LI>LIEF5</LI>                                                              
    <LI>LIEF6</LI></UL>                                                             
    <LI>LIEF1</LI>                                                                  
    <LI>LIEF2</LI>                                                                  
    <LI>LIEF3</LI></UL>                                                             
    <LI>BRANCH3</LI>                                                                
    <LI>BRANCH5</LI>                                                                
    <UL><LI>LIEF4</LI></UL></UL></UL>                                               
    11 row(s) retrieved
    Processing ...
    DROP TABLE TAB_A PURGE
    Processing ...
    DROP TABLE TEMP_TAB
    SELECT LV,RN,1+(NVL(LAG(LV) OVER ( ORDER BY RN ASC),0)-LV+1) step,
         lead(LV) OVER ( ORDER BY RN ASC NULLS LAST) next_lev,
         decode (lv-1,nvl(LAG(LV) OVER ( ORDER BY RN ASC),0),'<UL>','')||
         '<LI>'||NAME||'</LI>'||
         replace(
         RPAD(chr(10),1+(lv-NVL(lead(LV) OVER ( ORDER BY RN ASC),0))*5,'</UL>'),
         chr(10),
         ) AS HTML
    FROM TEMP_TAB A
    ORDER BY RN ASC
    /Bye Alessandro

  • How to use order by with hierarchical query

    I have a hierarchical query basically it brings back an organization chart. We start with a manager's id, get all that person's employees. If any of the employees is also a manager I want to get that person's employees and return them right after that person. I won't bother with the whole query but relevant part is:
           START WITH em.mgr_id = pi_mgr_id
          CONNECT BY nocycle PRIOR em.emp_id = em.mgr_id;Where pi_mgr_id is a parameter passed to the procedure and em is the alias for the emp_mgr_relationship table which contains emp_id and mgr_id. This works fine. What I want now is for the employees who work for the same manager to appear in name order. The table which contains the employee names is aliased as pe and the name column is called name1. I added the following:
           START WITH em.mgr_id = pi_mgr_id
          CONNECT BY nocycle PRIOR em.emp_id = em.mgr_id
            order by pe.name1;But that put the entire list in name order. What I want is for employees who work for the same manager to be in name order. Let's the manager whose organization I want is named Frank. What I'd like to get is this
    EMP_NAME    MGR_NAME
    Allen       Frank
    Beth        Frank
    Alex        Beth
    Charles     Beth
    Ed          Beth
    Dean        Frank
    George      Frank
    Benny       George
    David       George
    Sam         George
    Dan         Sam
    Harry       Sam
    John        Sam
    Terry       George
    James       Frank
    Ken         Frank
    Mike        Ken
    Warren      KenHow do I get the list in this order?
    Edited by: kendenny on Jul 28, 2010 7:31 AM

    Make use of ORDER SIBLINGS clause in hierarchial queries to set the order by child columns.
    START WITH em.mgr_id = pi_mgr_id
          CONNECT BY nocycle PRIOR em.emp_id = em.mgr_id
            *order siblings by name1;*

  • Help with MDX Query Result weirdness

    Hi,
    Feels like I'm posting a question every other day, hope I don't wear out my welcome.
    So I have a working query :
    with
    MEMBER Measures.[EmailCount] as IIF(ISEMPTY([Measures].[Tran Count]), 0 ,[Measures].[Tran Count])
    MEMBER Measures.AdvGroupTotal as
    SUM (EXISTING ([Dim IFA Details].[Parent Key].[Adviser Group] ,
    [Dim Date].[Fiscal].[Fiscal Year].&[FY 13/14]) , Measures.[Amount])
    MEMBER [Measures].[Income Range] as
    CASE
    WHEN Measures.AdvGroupTotal <= 10000 THEN '0-10000'
    WHEN Measures.AdvGroupTotal <= 50000 THEN '10001-50000'
    WHEN Measures.AdvGroupTotal <= 100000 THEN '50001-100000'
    WHEN Measures.AdvGroupTotal <= 200000 THEN '100001-200000'
    else '200000-'
    end
    SELECT { [Measures].[Amount] , Measures.[EmailCount], Measures.AdvGroupTotal, measures.[income range]}
    ON COLUMNS,
    [Dim IFA Details].[Parent Key].[Adviser Group].Members * [Dim Date].[Fiscal Quarter].children
    having Measures.AdvGroupTotal > 100
    on rows
    FROM [Income and Emails Cube]
    where
    ([Dim Date].[Fiscal].[Fiscal Year].&[FY 13/14]
    Great, gives me back what I expect
    So now I'm thinking, actually let's lose the Adviser Groups and just have it by Fiscal Quarter and Income Range, dropping that I lose my income range and get this:
    I figured its related to Income Range being a measure, so I tried making income range a calculated member of a dimension
    with
    MEMBER Measures.[EmailCount] as IIF(ISEMPTY([Measures].[Tran Count]), 0 ,[Measures].[Tran Count])
    MEMBER Measures.AdvGroupTotal as
    SUM (EXISTING ([Dim IFA Details].[Parent Key].[Adviser Group] ,
    [Dim Date].[Fiscal].[Fiscal Year].&[FY 13/14]) , Measures.[Amount])
    MEMBER [Dim IFA Details].[Parent Key].[Income Range] as
    CASE
    WHEN Measures.AdvGroupTotal <= 10000 THEN '0-10000'
    WHEN Measures.AdvGroupTotal <= 50000 THEN '10001-50000'
    WHEN Measures.AdvGroupTotal <= 100000 THEN '50001-100000'
    WHEN Measures.AdvGroupTotal <= 200000 THEN '100001-200000'
    else '200000-'
    end
    SELECT { [Measures].[Amount] , Measures.[EmailCount], Measures.AdvGroupTotal}
    ON COLUMNS,
    ( [Dim Date].[Fiscal Quarter].children, [Dim IFA Details].[Parent Key].[Income Range] )
    on rows
    FROM [Income and Emails Cube]
    where
    ([Dim Date].[Fiscal].[Fiscal Year].&[FY 13/14]
    This then came back with some unexpected results:
    The amount and email count are now the Income Range and still didnt get the income grouping I want.
    What am I doing wrong?
    Thanks for reading.
    Regards
    Jon

    Hi JLJ1976,
    According to your description, you have some issue when changing the measure into a dimension member. Right?
    In this scenario, the reason why you get the incorrect result set is you make a measure into dimension member. In your query, the Income Range is based on the Measure AdvGroup Total, and the AdvGroup Total value depends on how your dimension slice the cube.
    If you slice the cube on date members, you will get a much smaller AdvGroup Total value. So the Measure XXX return dynamic values because it always based on dimension slicer. For dimension members, they should be static values appear on axis to slice the cube
    data on a data. So you should make the Income Range into a calculated measure because it's based on a Quarter sliced Measure. Otherwise, it will return null value (in your query, it's the else part result) because you are measuring a measure.
    For more explanation about dimensions and Measures, please refer to links below:
    Measures and Measure Groups
    Introduction to Dimensions (Analysis Services - Multidimensional Data)
    Best Regards,
    Simon Hou
    TechNet Community Support

  • Help with hierarchical query

    I can't figure the right connect_by/start with operators for the following query.
    Here is the table:
    id, name, parent_id, type
    ==========================
    100 AAA 50 B
    50 BBB 25 B
    25 CCC 10 A
    20 DDD 5 B
    10 EEE 5 A
    5 FFF 1 A
    1 GGG A
    And here is how the result should look like
    id, name, youngerst_A
    ==========================
    100 AAA 25
    50 BBB 25
    20 DDD 5
    Your help will be greatly appreciated.
    George

    Hello George,
    you want something like that
    With Table_x As(Select 100 id, 'AAA' Name,   50 parent_id, 'B' Type From Dual Union All
                    Select  50 id, 'BBB' Name,   25 parent_id, 'B' Type From Dual Union All
                    Select  25 id, 'CCC' Name,   10 parent_id, 'A' Type From Dual Union All
                    Select  20 id, 'DDD' Name,    5 parent_id, 'B' Type From Dual Union All
                    Select  10 id, 'EEE' Name,    5 parent_id, 'A' Type From Dual Union All
                    Select   5 id, 'FFF' Name,    1 parent_id, 'A' Type From Dual Union All
                    Select   1 id, 'GGG' Name, Null parent_id, 'A' Type From Dual)
    SELECT ID
         , Name
         , YOUNGEST_A
      FROM (SELECT CONNECT_BY_ROOT(ID) As ID
                 , CONNECT_BY_ROOT(Name) As Name
                 , PARENT_ID As YOUNGEST_A
              FROM TABLE_X
             WHERE CONNECT_BY_ISLEAF = 1
             Start With Type = 'B'
            Connect BY ID = Prior PARENT_ID AND Type = 'B')
    Order BY ID Descoutput
            ID NAME YOUNGEST_A
           100 AAA          25
            50 BBB          25
            20 DDD           5Regards,
    Christian Balz

  • Problem with select query (results cant b displayed)

    SELECT url,SUM(data_received) xyz FROM logs GROUP BY url ORDER BY xyz desc
    when i triedthe above query in the worksheet it works fine but when i write same query in code i get this error.
    myjsp page has this code.
    <%while (rset.next())
    out.println("<tr>");
    out.println("<td>" +
    rset.getString(1) + "</td><td>" +
    rset.getInt(2) + "</td><td> " +
    "</td>");
    out.println("<tr>");
    %>
    This is the error
    500 Internal Server Error
    java.sql.SQLException: Invalid column name at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:138) at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:175) at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:240) at oracle.jdbc.driver.OracleStatement.get_column_index(OracleStatement.java:3201) at oracle.jdbc.driver.OracleResultSetImpl.findColumn(OracleResultSetImpl.java:1880) at oracle.jdbc.driver.ScrollableResultSet.findColumn(ScrollableResultSet.java:1308) at oracle.jdbc.driver.OracleResultSet.getInt(OracleResultSet.java:1618) at list_action._jspService(_list__action.java:67) [list_action.jsp] at com.orionserver[Oracle Containers for J2EE 10g (10.1.3.0.0) ].http.OrionHttpJspPage.service(OrionHttpJspPage.java:60) at oracle.jsp.runtimev2.JspPageTable.service(JspPageTable.java:416) at oracle.jsp.runtimev2.JspServlet.internalService(JspServlet.java:478) at oracle.jsp.runtimev2.JspServlet.service(JspServlet.java:401) at javax.servlet.http.HttpServlet.service(HttpServlet.java:856) at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) ].server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:719) at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) ].server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:376) at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) ].server.http.HttpRequestHandler.doProcessRequest(HttpRequestHandler.java:870) at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) ].server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:451) at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) ].server.http.HttpRequestHandler.serveOneRequest(HttpRequestHandler.java:218) at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) ].server.http.HttpRequestHandler.run(HttpRequestHandler.java:119) at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) ].server.http.HttpRequestHandler.run(HttpRequestHandler.java:112) at oracle.oc4j.network.ServerSocketReadHandler$SafeRunnable.run(ServerSocketReadHandler.java:260) at oracle.oc4j.network.ServerSocketAcceptHandler.procClientSocket(ServerSocketAcceptHandler.java:230) at oracle.oc4j.network.ServerSocketAcceptHandler.access$800(ServerSocketAcceptHandler.java:33) at oracle.oc4j.network.ServerSocketAcceptHandler$AcceptHandlerHorse.run(ServerSocketAcceptHandler.java:831) at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) ].util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:303) at java.lang.Thread.run(Thread.java:595)
    please help

    it is better to use  into table ....itab.
    dont go for joins if u r joining four tables .......
    it is better to for all entries.
    SELECT aauart awerks akdauf akdpos
    bftrmi baufnr bstlbez baufpl
    blead_aufnr bprodnet
    FROM aufk AS a
    INNER JOIN afko AS b
    ON baufnr EQ aaufnr
    INTO  TABLE i_data1
    WHERE a~auart IN s_auart
    AND a~kdauf IN s_vbeln
    AND a~werks EQ p_werks
    AND b~aufnr IN s_aufnr
    AND b~ftrmi IN s_ftrmi.
    if i_data1[] is not initial .
    if any sorting criteria is required based on primary keys write the sort statement here.
    select  crueck crmzhl
    cvornr carbid clmnga cxmnga
    crmnga cism04 cism05 cbudat
    d~kunnr
    e~arbpl
    FROM afru AS c inner join vbak AS d
    ON caufnr EQ aaufnr  innerjoin  crhd AS e
    like this u need to do...........................
    u have joined around five tables ...definetly that wont work
    endif.

  • CF9 Problems with Select * query, resulting in Value can not be converted to requested type.

    So, I work on a legacy CF web site and there are numerous SELECT * FROM USERS_TABLE queries all over the site.
    Well, we changed the structure of said table in the database on our Testing and Staging sites, with no issues.
    When we pushed up to our production environment and changed the structure of the production DB table, the server kept kicking back "Value can not be converted to requested type."
    After doing some searching out there, it looks like CF caches the structure of the table, and you either have to restart CF to clear it, or rename and then name-back the DSN to fix the issue.
    http://www.bennadel.com/blog/194-ColdFusion-Query-Error-Value-Can-Not-Be-Converted-To-Requ ested-Type.htm
    That said, this doesn't happen in our testing and staging environments - so what would be the difference?
    Is there some setting I need to change in the CF Admin to keep this from happening again?

    Also, if you can use a Stored Procedure to retrieve the data, do so.  Standard queries gets all the information, anyway, chokes bandwidth passing it all to the CF server, and forces the CF server to filter, sort, and format the data.  SPs tell the db server to get ONLY the data requested, and forces the db server to filter and sort the data, leaving only formatting to the CF server.
    That's not true. The only time CF messes with data returned from the DB is if there's a maxrows attribute, and the record set returnded from the DB has more than that number of records... which causes CF to truncate the recordset to the correct size before returning it. The DB might or might not stop sending rows down to CF after CF says "yeah, I've got all I want now".
    Other than that, for all intents and purposes all CF does with the SQL is pass it to the DB and wait for an answer. The only thing it does to the returned data is to create a CF record set ("query") with it... this does not involve any filtering and sorting.
    Adam

  • PROBLEM WITH HIERARCHICAL QUERY - PLEASE HELP

    I have got three tables :
    CREATE TABLE FIRM
    (FID INTEGER NOT NULL PRIMARY KEY,
    FNAME VARCHAR(40),
    FTYPE VARCHAR(3),
    MASTERID INTEGER );
    CREATE TABLE FACULTY
    (FAID INTEGER NOT NULL PRIMARY KEY,
    FANAME VARCHAR(40),
    FATYPE VARCHAR(3),
    MASTERID INTEGER );
    CREATE TABLE EMPLOYEE
         (EID INTEGER NOT NULL PRIMARY KEY,
    ENAME VARCHAR(20),
    ESURNAME VARCHAR(20),
         EJOB VARCHAR(3),
         MASTERID INTEGER );
    This is a hierarchical tree(or is ment to be, I,m complete rookie ) . Firm can be the root or can be slave to another firm. Faculty can be slave to firm, or to another faculty. Employee can be slave to faculty or to another employee(e.g. boss). This connections are specified by MASTERIDs.
    I need to write a procedure, which parameter would be node ID. It is meant to create a VIEW from this node as if it was a root (view of a subtree).
    I tried CONNECT BY clause but it works only on one table at a time and I have here three tables.
    I completely don,t know how to write it. Please help.

    create view hierarchy as
    select id, master_id, name from table1
    union all
    select id, master_id, name from table2
    union all
    select id, master_id, name from table3
    Then do your connect by query against hierarchy.
    It will not work in 8i (connect by on views not allowed), so you will need to materialize the view.
    Kirill

  • Performance issue: looping over queries with a query results set

    I have code that works, but I think I should be able to run the code faster. I could try a stored procedure but there are so many variables to set. I tried with wrapping cftransation around the code, but it didn't make a noticeable difference. I need to go through the data singularly to fill my query object.
    Here's an ABBREVIATED sample of the code:
    <cfset tot_AllActiveListing = QueryNew(
    "AnnounceNum, JP_PDLoc, JP_JS_Title, JP_JS_KWID, JP_JS, JP_Open, JP_Close, JP_CloseType, JP_CloseName, JP_PosNeed, JP_DirectHire, JP_Desc, JP_Draft, JP_Archived, JP_State, JP_AreaID, JP_AreaName, JP_AreaAlias, JP_Fac_SU, JP_Fac_Facility, JP_FAC_ID, JP_Grade1, JP_Grade2, JP_Grade3, JP_Grade4, JP_Grade5, JP_Posted, JP_TypeHire, JP_HRemail",
    "VARCHAR,VARCHAR,VARCHAR,INTEGER,INTEGER,TIMESTAMP,TIMESTAMP,INTEGER,VARCHAR,INTEGER,BIT,V ARCHAR,BIT,BIT,VARCHAR,INTEGER,VARCHAR,VARCHAR,VARCHAR,VARCHAR,INTEGER,VARCHAR,VARCHAR,VAR CHAR,VARCHAR,VARCHAR,TIMESTAMP,INTEGER,VARCHAR")
    />
    <cfquery name="getAllActiveListing" datasource="#request.at_datasource#">
        SELECT j.JOB_AnnounceNum, j.JOB_PDLoc, j.fk_JS_code, j.Job_JPOpen, j.Job_JPClose, j.fk_CloseType, j.JOB_JPPosNeed, j.JOB_DirectHire, j.JOB_JPDesc, j.Job_JPDraft, j.JOB_JPArchived, j.JOB_State,
        j.fk_FACID, j.Posted, j.JOB_IHSvITU, f.Fac_Area, f.Fac_ServiceUnit, f.fac_Facility, f.Fac_Addr1, f.Fac_Addr2, f.Fac_City, f.Fac_State, f.Fac_Zip
        from JOB_JP j INNER JOIN #generaldb#IHSFacility f
        ON j.fk_FACID  = f.Fac_ID
        WHERE
                JOB_JPDraft = 0
                and (Job_JPClose = #Now()# or Job_JPClose > #Now()# or fk_CloseType = 2 or fk_CloseType = 3)
                and (JOB_JPArchived = 0 or JOB_JPArchived IS NULL)
                 <cfif IsDefined("qAltPostID") and qAltPostID.recordcount gt "0">
                and JOB_AnnounceNum IN (<cfqueryparam list="yes" cfsqltype="CF_SQL_varchar" value="#ValueList(qAltPostID.fk_Job_AnnounceNum)#">)
                <cfelseif option is "JPPostListing" and StructKeyExists(session,"IHSUID")>
                and  j.WhoCreated = #session.IHSUID#
                 </cfif>
                 Order by j.Job_JPOpen desc
        </cfquery>
        <cfloop from="1" to="#session.getAllActiveListing.recordcount#" index="i">       
                <cfquery name="getAllActiveListingGrade" datasource="#request.at_datasource#">
                    SELECT fk_Job_AnnounceNum, Grade
                    from Job_JP_Grade
                    Where Job_JP_Grade.fk_Job_AnnounceNum = '#session.getAllActiveListing.Job_AnnounceNum[i]#'
                </cfquery>    
                <cfif IsDefined("session.getAllActiveListing") and session.getAllActiveListing.recordcount neq "0">       
                    <cfquery name="getAllActiveListingIHSArea" datasource="#at_datasource#">
                    SELECT JOBIHSArea_ID, JOBIHSArea_Name, JOBIHSArea_Alias
                    from JOB_IHSArea_LKUP
                    where JOBIHSArea_Alias = '#session.getAllActiveListing.Fac_Area[i]#'
                    </cfquery>
                </cfif>       
                <cfset session.getAllActiveListingGrade = getAllActiveListingGrade />
                <cfquery name="getAllActiveListingCloseName" datasource="#at_datasource#">
                SELECT JOB_CloseName
                from JOB_CloseType_LKUP
                where JOB_CloseType_LKUP.JOB_CloseType = #session.getAllActiveListing.fk_CloseType[i]#
                </cfquery>
                    <cfscript>                                       
                       newRow=QueryAddRow(tot_AllActiveListing);
                        QuerySetCell(tot_AllActiveListing, "AnnounceNum", "#session.getAllActiveListing.Job_AnnounceNum[i]#");
                        QuerySetCell(tot_AllActiveListing, "JP_PDLoc", "#session.getAllActiveListing.JOB_PDLoc[i]#");
                        QuerySetCell(tot_AllActiveListing, "JP_Draft", "#session.getAllActiveListing.Job_JPDraft[i]#");
                        QuerySetCell(tot_AllActiveListing, "JP_Archived", "#session.getAllActiveListing.Job_JParchived[i]#");
                        QuerySetCell(tot_AllActiveListing, "JP_Posted", "#session.getAllActiveListing.Posted[i]#");
                        QuerySetCell(tot_AllActiveListing, "JP_PosNeed", "#session.getAllActiveListing.JOB_JPPosNeed[i]#");
                        QuerySetCell(tot_AllActiveListing, "JP_DirectHire", "#session.getAllActiveListing.JOB_DirectHire[i]#");
                     </cfscript>       
            </cfloop>
    Any ideas will be greatly appreciated. If stored procedures are the best way to handle this and will run appreciably faster, I'll try it.
    Thanks.
    JoyRose

    Thanks for your reply.
    So now here is the entire code written with LEFT JOIN:
    <cfquery name="getAllActiveListing" datasource="#request.at_datasource#">
        SELECT j.JOB_AnnounceNum, j.JOB_PDLoc, j.fk_JS_code, j.Job_JPOpen, j.Job_JPClose, j.fk_CloseType, j.JOB_JPPosNeed, j.JOB_DirectHire, j.JOB_JPDesc, j.Job_JPDraft, j.JOB_JPArchived, j.JOB_State,
        j.fk_FACID, j.Posted, j.JOB_IHSvITU, f.Fac_Area, f.Fac_ServiceUnit, f.fac_Facility, f.Fac_Addr1, f.Fac_Addr2, f.Fac_City, f.Fac_State, f.Fac_Zip, g.Grade, a.JOBIHSArea_ID, a.JOBIHSArea_Name, a.JOBIHSArea_Alias, c.JOB_CloseName, s.Title, p.HRContact, p.HRContactType, e.Email, k.fk_KWID, k.fk_AnnounceNum, w.JOB_KWName, w.JOB_KWID
        from JOB_JP j INNER JOIN #generaldb#IHSFacility f
        ON j.fk_FACID  = f.Fac_ID
        LEFT OUTER JOIN JOB_JP_Grade g
        ON j.JOB_AnnounceNum = g.fk_Job_AnnounceNum
        LEFT OUTER JOIN JOB_IHSArea_LKUP a
        ON j.Fac_Area = a.JOBIHSArea_Alias
        LEFT OUTER JOIN JOB_CloseType_LKUP c
        ON j.fk_CloseType = c.JOB_CloseType
        LEFT OUTER JOIN JOB_Series_LKUP s
        ON j.fk_js_code = s.fk_js_code
        LEFT OUTER JOIN JOB_JPContacts p
        ON j.JOB_AnnounceNum = p.fk_Job_AnnounceNum
        LEFT OUTER JOIN #globalds#Email e
        ON p.HRContact = e.table_ID
        LEFT OUTER JOIN JOB_JPKW k
        ON j.JOB_AnnounceNum = k.fk_AnnounceNum
        LEFT OUTER JOIN JOB_KW_LKUP w
        ON k.fk_KWID = w.JOB_KWID 
        WHERE
                JOB_JPDraft = 0
                and (Job_JPClose = #Now()# or Job_JPClose > #Now()# or fk_CloseType = 2 or fk_CloseType = 3)
                and (JOB_JPArchived = 0 or JOB_JPArchived IS NULL)
                 <cfif IsDefined("qAltPostID") and qAltPostID.recordcount gt "0">
                and JOB_AnnounceNum IN (<cfqueryparam list="yes" cfsqltype="CF_SQL_varchar" value="#ValueList(qAltPostID.fk_Job_AnnounceNum)#">)
                <cfelseif option is "JPPostListing" and StructKeyExists(session,"IHSUID")>
                and  j.WhoCreated = #session.IHSUID#
                 </cfif>
                 Order by j.Job_JPOpen desc
        </cfquery>
    I'm concerned about the queries below that I converted to the LEFT JOIN code above..
    <cfquery name="getAllActiveListingHRContact" datasource="#at_datasource#">
                SELECT HRContact, HRContactType
                from JOB_JPContacts
                where fk_Job_AnnounceNum = '#session.getAllActiveListing.JOB_AnnounceNum[i]#'
                </cfquery>
                <cfif CompareNoCase(getAllActiveListingHRContact.HRContactType,"HRContactID") is 0>       
                    <cfquery name="getAllActiveListingHREmail" datasource="#globalds#">
                    SELECT Email
                    from Email
                    where Table_ID = #getAllActiveListingHRContact.HRContact#
                    </cfquery>
                    <cfset session.getAllActiveListingHREmail = getAllActiveListingHREmail />
                </cfif>
                <cfquery name="getAllActiveListingMasterKey" datasource="#at_datasource#">
                SELECT fk_KWID, fk_AnnounceNum, JOB_KWName, JOB_KWID
                from JOB_JPKW, JOB_KW_LKUP
                where JOB_JPKW.fk_AnnounceNum = '#session.getAllActiveListing.JOB_AnnounceNum[i]#'
                and JOB_KW_LKUP.JOB_KWID = JOB_JPKW.fk_KWID
                </cfquery>
    I appreciate your help with this.

  • Help required with a query

    Hi,
    I am sure this is not a very complex query but i am out of ideas today and so decided to post it. Here is my SQL:
    select cr.id, ri.report_name
    from category cr, report ri where ri.report_id = cr.id
    and
    cr.id in ('AC01','UP01','UP02','UP03','XD01','UP04','ED01','EB01','ES01','DL01','UV01');
    I would like my output to appear in the same format as is specified in the IN clause i.e. first 'AC01' then 'UP01' then 'UP02' then 'UP03' and so forth.
    Thanks in advance.

    Then your order by should be like this
    ORDER BY DECODE(cr.id, 'AC01', 1, 'UP01', 2, 'UP02', 3, 'UP03', 4, 'XD01', 5, 'UP04', 6, 'ED01', 7, 'EB01', 8, 'ES01', 9, 'DL01', 10, 'UV01', 11)

  • Help required with Hierarchical XSD design

    Can someone tell me whats wrong with this XSD? As you can see there are 26 levels of parent, child, grandchild........... The idea is that even if a child is missing, the relationship is not broken and an XML tag is still generated. This design is not working however
    <?xml version="1.0" encoding="UTF-8"?>
    <schema xmlns="http://www.w3.org/2001/XMLSchema"
    xmlns:nxsd="http://xmlns.oracle.com/pcbpel/nxsd"
    xmlns:tns="http://www.oracle.com/ias/processconnect"
    targetNamespace="http://www.oracle.com/ias/processconnect"
    elementFormDefault="qualified"
    attributeFormDefault="unqualified"
    nxsd:stream="chars"
    nxsd:version="NXSD">
    <element name="root_element">
    <complexType>
    <sequence>
    <!-- FILEHD -->
    <element name="FILEHD" type="tns:FILEHD" startsWith="FILEHD" maxOccurs="unbounded" nillable="true" >
    <complexType name="FILEHD">
    <sequence>
    <!-- <element name="RecordID" type="string" nxsd:style="fixedLength" nxsd:length="6" /> -->
    <element name="CustomerName" type="string" nxsd:style="fixedLength" nxsd:length="7" />
    <element name="VersionNumber" type="string" nxsd:style="fixedLength" nxsd:length="6" />
    <element name="CreationDate" type="string" nxsd:style="terminated" nxsd:terminatedBy="${eol}" />
    <complexType>
    <sequence>
    <!-- FILETL -->
    <element name="FILETL" type="tns:FILETL" startsWith="FILETL" maxOccurs="unbounded" nillable="true" >
    <complexType name="FILETL">
    <sequence>
    <!-- <element name="FiletlRecordID" type="string" nxsd:style="fixedLength" nxsd:length="6" /> -->
    <complexType>
    <sequence>
    <!-- CATID-->
    <element name="CATID" type="tns:CATID" startsWith="CATID" maxOccurs="unbounded" nillable="true" >
    <complexType name="CATID">
    <sequence>
    <!-- <element name="CatRecordID" type="string" nxsd:style="fixedLength" nxsd:length="6" /> -->
    <element name="CatalogueID" type="string" nxsd:style="fixedLength" nxsd:length="3" />
    <element name="VaxCatalogueName" type="string" nxsd:style="fixedLength" nxsd:length="70" />
    <element name="OpelCatalogueName" type="string" nxsd:style="terminated" nxsd:terminatedBy="${eol}" />
    <complexType>
    <sequence>
    <!-- FWDREF-->
    <element name="FWDREF" type="tns:FWDREF" startsWith="FWDREF" maxOccurs="unbounded" nillable="true" >
    <complexType name="FWDREF">
    <sequence>
    <!-- <element name="FwdRecordID" type="string" nxsd:style="fixedLength" nxsd:length="6" /> -->
    <element name="Filler" type="string" nxsd:style="fixedLength" nxsd:length="1" />
    <element name="FwdLanguageCode" type="string" nxsd:style="fixedLength" nxsd:length="2" />
    <element name="FwdCatllustRef" type="string" nxsd:style="terminated" nxsd:terminatedBy="${eol}" />
    <complexType>
    <sequence>
    <!-- SECTID-->
    <element name="SECTID" type="tns:SECTID" startsWith="SECTID" maxOccurs="unbounded" nillable="true" >
    <complexType name="SECTID">
    <sequence>
    <!-- <element name="SecRecordID" type="string" nxsd:style="fixedLength" nxsd:length="6" /> -->
    <element name="SectionCode" type="string" nxsd:style="fixedLength" nxsd:length="1" />
    <element name="SecLanguageCode" type="string" nxsd:style="fixedLength" nxsd:length="2" />
    <element name="SectionName" type="string" nxsd:style="terminated" nxsd:terminatedBy="${eol}" />
    <complexType>
    <sequence>
    <!-- ILLREF-->
    <element name="ILLREF" type="tns:ILLREF" startsWith="ILLREF" maxOccurs="unbounded" nillable="true" >
    <complexType name="ILLREF">
    <sequence>
    <!-- <element name="ILLRecordID" type="string" nxsd:style="fixedLength" nxsd:length="6" /> -->
    <element name="Effectivity" type="string" nxsd:style="fixedLength" nxsd:length="1" />
    <element name="IllustRef" type="string" nxsd:style="fixedLength" nxsd:length="8" />
    <element name="CatIllusRef" type="string" nxsd:style="terminated" nxsd:terminatedBy="${eol}" />
    <complexType>
    <sequence>
    <!-- SUBSEC-->
    <element name="SUBSEC" type="tns:SUBSEC" startsWith="SUBSEC" maxOccurs="unbounded" nillable="true" >
    <complexType name="SUBSEC">
    <sequence>
    <!-- <element name="SubsecRecordID" type="string" nxsd:style="fixedLength" nxsd:length="6" /> -->
    <element name="SubsecEffectivity" type="string" nxsd:style="fixedLength" nxsd:length="1" />
    <element name="SubsecLanguageCode" type="string" nxsd:style="fixedLength" nxsd:length="2" />
    <element name="SubsecName" type="string" nxsd:style="terminated" nxsd:terminatedBy="${eol}" />
    <complexType>
    <sequence>
    <!-- SUBSET-->
    <element name="SUBSET" type="tns:SUBSET" startsWith="SUBSET" maxOccurs="unbounded" nillable="true" >
    <complexType name="SUBSET">
    <sequence>
    <!-- <element name="SubsetRecordID" type="string" nxsd:style="fixedLength" nxsd:length="6" /> -->
    <element name="SubsetEffectivity" type="string" nxsd:style="fixedLength" nxsd:length="1" />
    <element name="SubsetTagCode" type="string" nxsd:style="fixedLength" nxsd:length="2" />
    <element name="SubsetTagText" type="string" nxsd:style="terminated" nxsd:terminatedBy="${eol}" />
    <complexType>
    <sequence>
    <!-- MAINHD-->
    <element name="MAINHD" type="tns:MAINHD" startsWith="MAINHD" maxOccurs="unbounded" nillable="true" >
    <complexType name="MAINHD">
    <sequence>
    <!-- <element name="MainRecordID" type="string" nxsd:style="fixedLength" nxsd:length="6" /> -->
    <element name="MainEffectivity" type="string" nxsd:style="fixedLength" nxsd:length="1" />
    <element name="MainLanguageCode" type="string" nxsd:style="fixedLength" nxsd:length="2" />
    <element name="MainHeadingText" type="string" nxsd:style="terminated" nxsd:terminatedBy="${eol}" />
    <complexType>
    <sequence>
    <!-- SUBHD-->
    <element name="SUBHD" type="tns:SUBHD" startsWith="SUB-HD" maxOccurs="unbounded" nillable="true" >
    <complexType name="SUBHD">
    <sequence>
    <!-- <element name="SubhdRecordID" type="string" nxsd:style="fixedLength" nxsd:length="6" /> -->
    <element name="SubhdEffectivity" type="string" nxsd:style="fixedLength" nxsd:length="1" />
    <element name="SubhdLanguageCode" type="string" nxsd:style="fixedLength" nxsd:length="2" />
    <element name="SubhdHeadingText" type="string" nxsd:style="terminated" nxsd:terminatedBy="${eol}" />
    <complexType>
    <sequence>
    <!-- SUBHT-->
    <element name="SUBHT" type="tns:SUB-HT" startsWith="SUB-HT" maxOccurs="unbounded" nillable="true" >
    <complexType name="SUBHT">
    <sequence>
    <!-- <element name="SubhtRecordID" type="string" nxsd:style="fixedLength" nxsd:length="6" /> -->
    <element name="SubhtEffectivity" type="string" nxsd:style="fixedLength" nxsd:length="1" />
    <element name="SubhtLanguageCode" type="string" nxsd:style="fixedLength" nxsd:length="2" />
    <element name="SubhtHeadingText" type="string" nxsd:style="terminated" nxsd:terminatedBy="${eol}" />
    <complexType>
    <sequence>
    <!-- NOTESTA-->
    <element name="NOTESTA" type="tns:NOTESTA" startsWith="NOTE-S" maxOccurs="unbounded" nillable="true" >
    <complexType name="NOTESTA">
    <sequence>
    <!-- <element name="NotestaRecordID" type="string" nxsd:style="fixedLength" nxsd:length="6" /> -->
    <element name="NotestaEffectivity" type="string" nxsd:style="fixedLength" nxsd:length="1" />
    <element name="NotestaLanguageCode" type="string" nxsd:style="fixedLength" nxsd:length="2" />
         <element name="NotestaNoteWord" type="string" nxsd:style="fixedLength" nxsd:length="15" />
    <element name="NotestaNotetext" type="string" nxsd:style="terminated" nxsd:terminatedBy="${eol}" />
    <complexType>
    <sequence>
    <!-- NOTEMID-->
    <element name="NOTEMID" type="tns:NOTEMID" startsWith="NOTE-M" maxOccurs="unbounded" nillable="true" >
    <complexType name="NOTEMID">
    <sequence>
    <!-- <element name="NotemidRecordID" type="string" nxsd:style="fixedLength" nxsd:length="6" /> -->
    <element name="NotemidEffectivity" type="string" nxsd:style="fixedLength" nxsd:length="1" />
    <element name="NotemidLanguageCode" type="string" nxsd:style="fixedLength" nxsd:length="2" />
    <element name="NotemidNotetext" type="string" nxsd:style="terminated" nxsd:terminatedBy="${eol}" />
    <complexType>
    <sequence>
    <!-- NOTEEND-->
    <element name="NOTEEND" type="tns:NOTEEND" startsWith="NOTE-E" maxOccurs="unbounded" nillable="true" >
    <complexType name="NOTEEND">
    <sequence>
    <!-- <element name="NoteendRecordID" type="string" nxsd:style="fixedLength" nxsd:length="6" /> -->
    <element name="NoteendEffectivity" type="string" nxsd:style="fixedLength" nxsd:length="1" />
    <element name="NoteendLanguageCode" type="string" nxsd:style="fixedLength" nxsd:length="2" />
    <element name="NoteendNotetext" type="string" nxsd:style="terminated" nxsd:terminatedBy="${eol}" />
    <complexType>
    <sequence>
    <!-- DDESC-->
    <element name="DDESC" type="tns:DDESC" startsWith="D-DESC" maxOccurs="unbounded" nillable="true" >
    <complexType name="DDESC">
    <sequence>
    <!-- <element name="DdescRecordID" type="string" nxsd:style="fixedLength" nxsd:length="6" /> -->
    <element name="DdescEffectivity" type="string" nxsd:style="fixedLength" nxsd:length="1" />
         <element name="DdescIllusxref" type="string" nxsd:style="fixedLength" nxsd:length="3" />
         <element name="DdescQnty" type="string" nxsd:style="fixedLength" nxsd:length="2" />
         <element name="DdescFootxref" type="string" nxsd:style="fixedLength" nxsd:length="2" />
    <element name="DdescPartnbr" type="string" nxsd:style="fixedLength" nxsd:length="12" />
         <element name="DdescCatnbr" type="string" nxsd:style="fixedLength" nxsd:length="12" />
         <element name="DdescCatsym" type="string" nxsd:style="fixedLength" nxsd:length="1" />
    <element name="DdescLhdRhd" type="string" nxsd:style="terminated" nxsd:terminatedBy="${eol}" />
    <complexType>
    <sequence>
    <!-- DUSAGE-->
    <element name="DUSAGE" type="tns:DUSAGE" startsWith="D-USG" maxOccurs="unbounded" nillable="true" >
    <complexType name="DUSAGE">
    <sequence>
    <!-- <element name="DusgRecordID" type="string" nxsd:style="fixedLength" nxsd:length="6" /> -->
    <element name="DusgEffectivity" type="string" nxsd:style="fixedLength" nxsd:length="1" />
    <element name="DusgLanguageCode" type="string" nxsd:style="fixedLength" nxsd:length="2" />
    <element name="DusgUsgtext" type="string" nxsd:style="terminated" nxsd:terminatedBy="${eol}" />
    <complexType>
    <sequence>
    <!-- DUSGTAG-->
    <element name="DUSGTAG" type="tns:DUSGTAG" startsWith="D-USGT" maxOccurs="unbounded" nillable="true" >
    <complexType name="DUSGTAG">
    <sequence>
    <!-- <element name="DusgtRecordID" type="string" nxsd:style="fixedLength" nxsd:length="6" /> -->
    <element name="DusgtEffectivity" type="string" nxsd:style="fixedLength" nxsd:length="1" />
    <element name="DusgtTagCode" type="string" nxsd:style="fixedLength" nxsd:length="2" />
    <element name="DusgtTagtext" type="string" nxsd:style="terminated" nxsd:terminatedBy="${eol}" />
    <complexType>
    <sequence>
    <!-- DRANGE-->
    <element name="DRANGE" type="tns:DRANGE" startsWith="D-RGE" maxOccurs="unbounded" nillable="true" >
    <complexType name="DRANGE">
    <sequence>
    <!-- <element name="DrgeRecordID" type="string" nxsd:style="fixedLength" nxsd:length="6" /> -->
    <element name="DrgeEffectivity" type="string" nxsd:style="fixedLength" nxsd:length="1" />
    <element name="DrgeTagCode" type="string" nxsd:style="fixedLength" nxsd:length="2" />
    <element name="DrgeTagtext" type="string" nxsd:style="terminated" nxsd:terminatedBy="${eol}" />
    <complexType>
    <sequence>
    <!-- DES0-->
    <element name="DES0" type="tns:DES0" startsWith="DES0" maxOccurs="unbounded" nillable="true" >
    <complexType name="DES0">
    <sequence>
    <!-- <element name="Des0RecordID" type="string" nxsd:style="fixedLength" nxsd:length="6" /> -->
    <element name="Des0Effectivity" type="string" nxsd:style="fixedLength" nxsd:length="1" />
    <element name="Des0LanguageCode" type="string" nxsd:style="fixedLength" nxsd:length="2" />
    <element name="Des0DescText" type="string" nxsd:style="terminated" nxsd:quotedBy="&lt;" nxsd:terminatedBy="${eol}" />
    <complexType>
    <sequence>
    <!-- DES1-->
    <element name="DES1" type="tns:DES1" startsWith="DES1" maxOccurs="unbounded" nillable="true" >
    <complexType name="DES1">
    <sequence>
    <!-- <element name="Des1RecordID" type="string" nxsd:style="fixedLength" nxsd:length="6" /> -->
    <element name="Des1Effectivity" type="string" nxsd:style="fixedLength" nxsd:length="1" />
    <element name="Des1LanguageCode" type="string" nxsd:style="fixedLength" nxsd:length="2" />
    <element name="Des1DescText" type="string" nxsd:style="terminated" nxsd:quotedBy="&lt;" nxsd:terminatedBy="${eol}" />
    <complexType>
    <sequence>
    <!-- DES2-->
    <element name="DES2" type="tns:DES2" startsWith="DES2" maxOccurs="unbounded" nillable="true" >
    <complexType name="DES2">
    <sequence>
    <!-- <element name="Des2RecordID" type="string" nxsd:style="fixedLength" nxsd:length="6" /> -->
    <element name="Des2Effectivity" type="string" nxsd:style="fixedLength" nxsd:length="1" />
    <element name="Des2LanguageCode" type="string" nxsd:style="fixedLength" nxsd:length="2" />
    <element name="Des2DescText" type="string" nxsd:style="terminated" nxsd:quotedBy="&lt;" nxsd:terminatedBy="${eol}" />
    <complexType>
    <sequence>
    <!-- DES3-->
    <element name="DES3" type="tns:DES3" startsWith="DES3" maxOccurs="unbounded" nillable="true" >
    <complexType name="DES3">
    <sequence>
    <!-- <element name="Des3RecordID" type="string" nxsd:style="fixedLength" nxsd:length="6" /> -->
    <element name="Des3Effectivity" type="string" nxsd:style="fixedLength" nxsd:length="1" />
    <element name="Des3LanguageCode" type="string" nxsd:style="fixedLength" nxsd:length="2" />
    <element name="Des3DescText" type="string" nxsd:style="terminated" nxsd:terminatedBy="${eol}" />
    <complexType>
    <sequence>
    <!-- DES4-->
    <element name="DES4" type="tns:DES4" startsWith="DES4" maxOccurs="unbounded" nillable="true" >
    <complexType name="DES4">
    <sequence>
    <!-- <element name="Des4RecordID" type="string" nxsd:style="fixedLength" nxsd:length="6" /> -->
    <element name="Des4Effectivity" type="string" nxsd:style="fixedLength" nxsd:length="1" />
    <element name="Des4LanguageCode" type="string" nxsd:style="fixedLength" nxsd:length="2" />
    <element name="Des4DescText" type="string" nxsd:style="terminated" nxsd:terminatedBy="${eol}" />
    <complexType>
    <sequence>
    <!-- DEST-->
    <element name="DEST" type="tns:DEST" startsWith="DEST" maxOccurs="unbounded" nillable="true" >
    <complexType name="DEST">
    <sequence>
    <!-- <element name="DestRecordID" type="string" nxsd:style="fixedLength" nxsd:length="6" /> -->
    <element name="DestEffectivity" type="string" nxsd:style="fixedLength" nxsd:length="1" />
    <element name="DestTagCode" type="string" nxsd:style="fixedLength" nxsd:length="2" />
    <element name="DestTagText" type="string" nxsd:style="terminated" nxsd:terminatedBy="${eol}" />
    <complexType>
    <sequence>
    <!-- FOOTNT-->
    <element name="FOOTNT" type="tns:FOOTNT" startsWith="FOOTNT" maxOccurs="unbounded" nillable="true" >
    <complexType name="FOOTNT">
    <sequence>
    <!-- <element name="FootntRecordID" type="string" nxsd:style="fixedLength" nxsd:length="6" /> -->
    <element name="FootntEffectivity" type="string" nxsd:style="fixedLength" nxsd:length="1" />
    <element name="FootntLangCode" type="string" nxsd:style="fixedLength" nxsd:length="2" />
         <element name="FootntXref" type="string" nxsd:style="fixedLength" nxsd:length="2" />
    <element name="FootntText" type="string" nxsd:style="terminated" nxsd:terminatedBy="${eol}" />
    <complexType>
    <sequence>
    <!-- CATEND-->
    <element name="CATEND" type="tns:CATEND" startsWith="CATEND" maxOccurs="unbounded" nillable="true" >
    <complexType name="CATEND">
    <sequence>
    <!-- <element name="CatendRecordID" type="string" nxsd:style="fixedLength" nxsd:length="6" /> -->
    <element name="CatendCatID" type="string" nxsd:style="terminated" nxsd:terminatedBy="${eol}" />
    </sequence>
    </complexType>
    </element>
    </sequence>
    </complexType>
    </sequence>
    </complexType>
    </element>
    </sequence>
    </complexType>
    </sequence>
    </complexType>
    </element>
    </sequence>
    </complexType>
    </sequence>
    </complexType>
    </element>
    </sequence>
    </complexType>
    </sequence>
    </complexType>
    </element>
    </sequence>
    </complexType>
    </sequence>
    </complexType>
    </element>
    </sequence>
    </complexType>
    </sequence>
    </complexType>
    </element>
    </sequence>
    </complexType>
    </sequence>
    </complexType>
    </element>
    </sequence>
    </complexType>
    </sequence>
    </complexType>
    </element>
    </sequence>
    </complexType>
    </sequence>
    </complexType>
    </element>
    </sequence>
    </complexType>
    </sequence>
    </complexType>
    </element>
    </sequence>
    </complexType>
    </sequence>
    </complexType>
    </element>
    </sequence>
    </complexType>
    </sequence>
    </complexType>
    </element>
    </sequence>
    </complexType>
    </sequence>
    </complexType>
    </element>
    </sequence>
    </complexType>
    </sequence>
    </complexType>
    </element>
    </sequence>
    </complexType>
    </sequence>
    </complexType>
    </element>
    </sequence>
    </complexType>
    </sequence>
    </complexType>
    </element>
    </sequence>
    </complexType>
    </sequence>
    </complexType>
    </element>
    </sequence>
    </complexType>
    </sequence>
    </complexType>
    </element>
    </sequence>
    </complexType>
    </sequence>
    </complexType>
    </element>
    </sequence>
    </complexType>
    </sequence>
    </complexType>
    </element>
    </sequence>
    </complexType>
    </sequence>
    </complexType>
    </element>
    </sequence>
    </complexType>
    </sequence>
    </complexType>
    </element>
    </sequence>
    </complexType>
    </sequence>
    </complexType>
    </element>
    </sequence>
    </complexType>
    </sequence>
    </complexType>
    </element>
    </sequence>
    </complexType>
    </sequence>
    </complexType>
    </element>
    </sequence>
    </complexType>
              </element>
              </schema>

    I would suggest you should start with much smaller schema or to test step-by-step on the way of expanding the schema : not only to make sure it validates what is intended for but to make sure the schema itself being correct.
    I have only read through the first tens of lines and there are already "many" fundamental errors in schema construction.
    Take this starting fragment.
    <!-- taken from the orignal post -->
    <element name="root_element">
    <complexType>
    <sequence>
    <!-- FILEHD -->
    <element name="FILEHD" type="tns:FILEHD" startsWith="FILEHD" maxOccurs="unbounded" nillable="true" >
    <complexType name="FILEHD">
    <sequence>
    <!-- <element name="RecordID" type="string" nxsd:style="" /> -->
    <element name="CustomerName" type="string" nxsd:style="" />
    <element name="VersionNumber" type="string" nxsd:style="" />
    <element name="CreationDate" type="string" nxsd:style="" />
    <complexType>
    <sequence>
    <!-- FILETL -->
    <element name="FILETL" type="tns:FILETL" startsWith="FILETL" maxOccurs="unbounded" nillable="true" >
    <complexType name="FILETL">
    <sequence>
    <!-- etc etc... -->[1] What is the attribute startsWith which should be defined in the schema namespace (http://www.w3.org/2001/XMLSchema). Where do you get the idea it means something in the "element" element? What does it mean? I ask because I think it is wrong.
    [2] And then type="tns:FILETL" attribute in the element. I think I get the idea that you want to refer to the following complexType named="FILETL". But this is wrong construction. It won't never work for multiple reason.
    [2.1] Either you close the element right away and take out what follows and make the latter as a top-level complexType element named "FILETL", or
    [2.2] Or you take out the name attribute in the following line of complexType. As such, it is a local type (or an anonymous type) which is forbidden to have a name attribute. That's strict and forbidden.
    [3] And then after element named CreationDate which has a well-defined type string and is closed. But immediately after, you have complexType... This is not an acceptable construction. You cannot have complexType (or simpleType for that matter) as immediate child of sequence (or any other component like choice or all etc.) That is fatal error. The schema processing engine cannot go any further.
    After the quoted fragment, you probably have a lot of similar constructions that you've to correct them all to begin with. There is a very slim chance to furnish you further help if those kinds of errors appear all over the places.

  • Hierarchical query with multiple roots

    Hi,
    I'm trying to write a sql query to find blocking lock in database. The idea is to get the blocker in 1st column, comma separated list of waiters in 2nd column and number of waiters in 3rd column.
    As of now i use below query to get a tree structure
    WITH lk AS
         (SELECT  blocking_session||' (Inst-'||blocking_instance || ')' blocker,
                 SID||' (Inst-'||inst_id || ')' waiter
            FROM gv$session
           WHERE blocking_instance IS NOT NULL AND blocking_session IS NOT NULL)
    SELECT     LPAD (' ', 2 * (LEVEL - 1)) || waiter lock_tree
          FROM (SELECT *
                  FROM lk
                UNION ALL
                SELECT DISTINCT 'root', blocker
                           FROM lk
                          WHERE blocker NOT IN (SELECT waiter
                                                  FROM lk))
    CONNECT BY PRIOR waiter = blocker
    START WITH blocker = 'root';
    Result:-
    ===========
    LOCK_TREE
    1966 (Inst-1)
      908 (Inst-1)
      1906 (Inst-1)
      1900 (Inst-1)
    981 (Inst-1)
      921 (Inst-1)
      937 (Inst-1)
      962 (Inst-1)
      1889 (Inst-1)
      1904 (Inst-1)
      974 (Inst-1) But what i expect is like below. My below query works when there is only one root blocker, but fails when there are multiple root node.
    WITH lk AS
         (SELECT blocking_session || '(Inst-' || blocking_instance || ')' blocker,
                 SID || '(Inst-' || inst_id || ')' waiter
            FROM gv$session
           WHERE blocking_instance IS NOT NULL AND blocking_session IS NOT NULL)
    SELECT     blocker, SUBSTR (SYS_CONNECT_BY_PATH (waiter, ';'), 2) waiters
          FROM (SELECT   blocker, waiter, ROW_NUMBER () OVER (ORDER BY waiter)
                                                                              val
                    FROM lk
                GROUP BY blocker, waiter)
         WHERE CONNECT_BY_ISLEAF = 1
    START WITH val = 1
    CONNECT BY PRIOR val = val - 1
    Result:-
    ===========
      WAITERS# BLOCKER                                                                                 WAITERS
             3 981(Inst-1)                                                                             1904(Inst-1);921(Inst-1);937(Inst-1)
    ....lot of duplicates
    expected result:-
    ===========
      WAITERS# BLOCKER                                                                                 WAITERS
             4 981(Inst-1)                                                                             1904(Inst-1);921(Inst-1);937(Inst-1);974(Inst-1)
             3 1966(Inst-1)                                                                             908 (Inst-1);1906 (Inst-1);1900 (Inst-1) can you please help me correct above query or suggest other ways to archive this result.
    Thanks in advance
    MidhunGT

    Hi All,
    Thank you all for your support. I never knew these many ways to see blocking lock in database :)
    Somehow i was able get the desired result for my specific requirement with below query
    sql> WITH lk AS
      2       (SELECT blocking_session || ' (Inst-' || blocking_instance
      3               || ')' blocker,
      4               SID || ' (Inst-' || inst_id || ')' waiter
      5          FROM gv$session
      6         WHERE blocking_instance IS NOT NULL AND blocking_session IS NOT NULL)
      7  SELECT     blocker,
      8             LTRIM
      9                (MAX (SYS_CONNECT_BY_PATH (waiter, ','))KEEP (DENSE_RANK LAST ORDER BY cnt),
    10                 ','
    11                ) AS waiters,
    12             MAX (cnt) waiters#
    13        FROM (SELECT blocker, waiter,
    14                     ROW_NUMBER () OVER (PARTITION BY blocker ORDER BY waiter)
    15                                                                         AS cnt
    16                FROM lk)
    17    GROUP BY blocker
    18  CONNECT BY cnt - 1 = PRIOR cnt AND blocker = PRIOR blocker
    19  START WITH cnt = 1;
    BLOCKER         WAITERS                                                                            WAITERS#
    1946 (Inst-1)   1987 (Inst-1),879 (Inst-1),910 (Inst-1)                                                3
    930 (Inst-1)    1919 (Inst-1),1945 (Inst-1),1953 (Inst-1),1983 (Inst-1)                                4please advice, if any scope for improvement
    Thanks and Regards,
    MidhunGT

  • No parent without child (hierarchical query)

    Dear Gurus,
    I have a problem with Hierarchical query. That is, I want show only those PARENTS who have child.
    Table structure:
    Business Unit
    BU_NO     BU_NAME BU_NO_PARENT
    1 Marketing
    2 Research 1
    3 Planning 1
    4 Strategic 3
    5 Admin
    6 Human Resources 5
    7 Accounts 5
    Employee
    EMP_NO     ENAME BU_NO
    7369 SMITH 2
    7499 ALLEN 6
    7521 WARD 1
    7566 CLARK 5
    7654 MARTIN 7
    7698 BLAKE 2
    7788 SCOTT 7
    7839 KING 5
    I have to show the list of employees with BU. But exclude those BU which have no employee. My output should be like this:
    NAME
    Marketing
    -----WARD
    -----Research
    ----------SMITH
    Admin
    -----CLARK
    -----KING
    -----Human Resources
    ----------ALLEN
    -----Accounts
    ----------MARTIN
    ----------SCOTT
    For this I've written a query but it shows all BUs (with employee and without employee)
    Query is:
    SELECT LPAD(obj_name, LENGTH(obj_name)+(LEVEL-1)*5, '-') obj_name
    FROM
    (SELECT 'B'||bu_no obj_no, bu_name obj_name, 'B'||bu_no_parent parent_obj_no FROM hr_bu
    UNION ALL
    SELECT TO_CHAR(emp_no), ename, 'B'||bu_no FROM hr_emp)
    START WITH parent_obj_no = 'B'
    CONNECT BY PRIOR obj_no = parent_obj_no;
    Can you please help me in writing query to eliminate BU from output where no employee is working.
    Thanks.

    Hi,
    To exclude certain nodes without excluding their descendants, simply use a WHERE-Clause, like this:
    SELECT     LPAD     ( obj_name
              , LENGTH (obj_name) + (LEVEL-1) * 5
              ) obj_name
    FROM     (
         SELECT     'B' || bu_no          obj_no
         ,     bu_name           obj_name
         ,     'B' || bu_no_parent     parent_obj_no
         FROM     hr_bu
         UNION ALL
         SELECT     TO_CHAR (emp_no)
         ,     ename
         ,     'B' || bu_no
         FROM     hr_emp
         ) u
    WHERE     obj_no     NOT LIKE 'B%'
    OR     EXISTS     (     -- Begin correalated sub-query to find emps in this bu
              SELECT     0
              FROM     hr_emp
              WHERE     'B' || bu_no     = u.obj_no
              )     -- End correalated sub-query to find emps in this bu
    START WITH     parent_obj_no     = 'B'
    CONNECT BY     PRIOR obj_no     = parent_obj_no;Output:
    OBJ_NAME
    Marketing
    -----Research
    ----------SMITH
    ----------BLAKE
    -----WARD
    Admin
    -----Human Resources
    ----------ALLEN
    -----Accounts
    ----------MARTIN
    ----------SCOTT
    -----CLARK
    -----KINGThe results above include employee Blake, who was not included in your sample output, but I assume he was left off by mistake.
    The solution above may produce misleading output. For example, if you remove employee Ward from your sample data, then the Marketing unit will not appear, but the Research unit will still appear (as you want), but Reasearch will be at LEVEL=2, so you may get the output below, which seems to indicate that Research is a child of Admin:
    OBJ_NAME
    Admin
    -----Human Resources
    ----------ALLEN
    -----Accounts
    ----------MARTIN
    ----------SCOTT
    -----CLARK
    -----KING
    -----Research
    ----------SMITH
    ----------BLAKETo avoid this kind of confusion, I would display SYS_CONNECT_BY_PATH (obj_name) rather than obj_name, or I would include all Business Units that were ancestors of Business units that have employees.

Maybe you are looking for