Multiple columns in connect by prior

Hi,
I have data something like below
SKU:
ITEM LOC PARENT_ITEM PARENT_LOC
NULL NULL A 001
A 001 NULL NULL
A 001 NULL NULL
NULL NULL D 002
D 002 NULL NULL
D 002 NULL NULL
And I need output like this
ITEM LOC PARENT_ITEM PARENT_LOC
NULL NULL A 001
B 001 A 001
C 001 A 001
NULL NULL D 002
E 002 D 002
F 002 D 002
And I tried it with connect by prior.
Select CONNECT_BY_ROOT as item,loc,parent_item,parent_loc FROM
sku
start with parent_item is null and parent_loc is null
connect by prior parent_item = item and parent_loc = loc
But I am getting only parent record not others.
ITEM LOC PARENT_ITEM PARENT_LOC
A NULL A 001
D NULL D 002
I should apply CONNECT_BY_ROOT and connect by PRIOR on set (like item at loc).
Please help..
Thanks...

Hi ,
Can some one please explain me how to comprehend/understand  multiple conditions in connect by prior conditions with some example data.
I am creating a table like this
CREATE TABLE FAMiLY_TREE
GRAND_FATHERID number,
FATHER_ID number,
SON_ID number,
person_name varchar(20)
INSERT INTO  FAMILY_TREE (GRAND_FATHERID ,FATHER_ID , SON_ID , PERSON_NAME ) VALUES
(NULL, NULL , 5 , 'Mr X ' );
INSERT INTO  FAMILY_TREE (GRAND_FATHERID ,FATHER_ID , SON_ID , PERSON_NAME ) VALUES
(null, 5 , 6 , 'Dave' );
INSERT INTO  FAMILY_TREE (GRAND_FATHERID ,FATHER_ID , SON_ID , PERSON_NAME ) VALUES
(5, 6 , 7 , 'Vinny' );
INSERT INTO  FAMILY_TREE (GRAND_FATHERID ,FATHER_ID , SON_ID , PERSON_NAME ) VALUES
(5, 6 , 14 , 'Omy' );
INSERT INTO  FAMILY_TREE (GRAND_FATHERID ,FATHER_ID , SON_ID , PERSON_NAME ) VALUES
(5, 6 , 15 , 'Vijjy' );
INSERT INTO  FAMILY_TREE (GRAND_FATHERID ,FATHER_ID , SON_ID , PERSON_NAME ) VALUES
(6, 7 , 8 , 'Vicky' );
INSERT INTO  FAMILY_TREE (GRAND_FATHERID ,FATHER_ID , SON_ID , PERSON_NAME ) VALUES
(6, 7 , 9 , 'Varis' );
INSERT INTO  FAMILY_TREE (GRAND_FATHERID ,FATHER_ID , SON_ID , PERSON_NAME ) VALUES
(7, 8 , 10 , 'Vshnu' );
INSERT INTO  FAMILY_TREE (GRAND_FATHERID ,FATHER_ID , SON_ID , PERSON_NAME ) VALUES
(7, 8 , 11 , 'dyna' );
INSERT INTO  FAMILY_TREE (GRAND_FATHERID ,FATHER_ID , SON_ID , PERSON_NAME ) VALUES
(8, 10 , 14 , 'Marry' );
INSERT INTO  FAMILY_TREE (GRAND_FATHERID ,FATHER_ID , SON_ID , PERSON_NAME ) VALUES
(8, 10 , 15 , 'Mac' );
INSERT INTO  FAMILY_TREE (GRAND_FATHERID ,FATHER_ID , SON_ID , PERSON_NAME ) VALUES
(7, 9 , 12 , 'Garry' );
INSERT INTO  FAMILY_TREE (GRAND_FATHERID ,FATHER_ID , SON_ID , PERSON_NAME ) VALUES
(7, 9 , 13 , 'Ganny' );
SELECT
LPAD(' ', LEVEL*3) || PERSON_NAME FROM FAMILY_TREE
START WITH SON_ID= 6
CONNECT BY PRIOR SON_ID = FATHER_ID
AND PRIOR FATHER_ID = GRAND_FATHERID ;
SELECT
LPAD(' ', LEVEL*3) || PERSON_NAME FROM FAMILY_TREE
START WITH SON_ID= 6
CONNECT BY PRIOR SON_ID = FATHER_ID ;
Both These query return the same o/p
   Dave
      Vinny
         Vicky
            Vshnu
               Marry
               Mac
            dyna
         Varis
            Garry
            Ganny
      Omy
      Vijjy
Can some one please explain me comprehension of both these query or give me a example where i can understand multiple connect by prior conditions
Thanks

Similar Messages

  • Understanding multiple conditions in connect by prior clause Oracle

    Hi ,
    Can some one please explain me how to comprehend/understand  multiple conditions in connect by prior conditions with some example data.
    I am creating a table like this
    CREATE TABLE FAMiLY_TREE
    GRAND_FATHERID number,
    FATHER_ID number,
    SON_ID number,
    person_name varchar(20)
    INSERT INTO  FAMILY_TREE (GRAND_FATHERID ,FATHER_ID , SON_ID , PERSON_NAME ) VALUES
    (NULL, NULL , 5 , 'Mr X ' );
    INSERT INTO  FAMILY_TREE (GRAND_FATHERID ,FATHER_ID , SON_ID , PERSON_NAME ) VALUES
    (null, 5 , 6 , 'Dave' );
    INSERT INTO  FAMILY_TREE (GRAND_FATHERID ,FATHER_ID , SON_ID , PERSON_NAME ) VALUES
    (5, 6 , 7 , 'Vinny' );
    INSERT INTO  FAMILY_TREE (GRAND_FATHERID ,FATHER_ID , SON_ID , PERSON_NAME ) VALUES
    (5, 6 , 16 , 'Omy' );
    INSERT INTO  FAMILY_TREE (GRAND_FATHERID ,FATHER_ID , SON_ID , PERSON_NAME ) VALUES
    (5, 6 , 17 , 'Vijjy' );
    INSERT INTO  FAMILY_TREE (GRAND_FATHERID ,FATHER_ID , SON_ID , PERSON_NAME ) VALUES
    (6, 7 , 8 , 'Vicky' );
    INSERT INTO  FAMILY_TREE (GRAND_FATHERID ,FATHER_ID , SON_ID , PERSON_NAME ) VALUES
    (6, 7 , 9 , 'Varis' );
    INSERT INTO  FAMILY_TREE (GRAND_FATHERID ,FATHER_ID , SON_ID , PERSON_NAME ) VALUES
    (7, 8 , 10 , 'Vshnu' );
    INSERT INTO  FAMILY_TREE (GRAND_FATHERID ,FATHER_ID , SON_ID , PERSON_NAME ) VALUES
    (7, 8 , 11 , 'dyna' );
    INSERT INTO  FAMILY_TREE (GRAND_FATHERID ,FATHER_ID , SON_ID , PERSON_NAME ) VALUES
    (8, 10 , 14 , 'Marry' );
    INSERT INTO  FAMILY_TREE (GRAND_FATHERID ,FATHER_ID , SON_ID , PERSON_NAME ) VALUES
    (8, 10 , 15 , 'Mac' );
    INSERT INTO  FAMILY_TREE (GRAND_FATHERID ,FATHER_ID , SON_ID , PERSON_NAME ) VALUES
    (7, 9 , 12 , 'Garry' );
    INSERT INTO  FAMILY_TREE (GRAND_FATHERID ,FATHER_ID , SON_ID , PERSON_NAME ) VALUES
    (7, 9 , 13 , 'Ganny' );
    SELECT
    LPAD(' ', LEVEL*3) || PERSON_NAME FROM FAMILY_TREE
    START WITH SON_ID= 6
    CONNECT BY PRIOR SON_ID = FATHER_ID
    AND PRIOR FATHER_ID = GRAND_FATHERID ;
    SELECT
    LPAD(' ', LEVEL*3) || PERSON_NAME FROM FAMILY_TREE
    START WITH SON_ID= 6
    CONNECT BY PRIOR SON_ID = FATHER_ID ;
    Both These query return the same o/p
       Dave
          Vinny
             Vicky
                Vshnu
                   Marry
                   Mac
                dyna
             Varis
                Garry
                Ganny
          Omy
          Vijjy
    Can some one please explain me comprehension of both these query or give me a example where i can understand multiple connect by prior conditions
    Thanks

    Maybe (something to play with)
    with
    family_tree as
    (select 'Green' family,null ancestor,1 person,'Mr X' person_name,1900 born from dual union all
    select 'Green',1,2,'Dave',1920 from dual union all
    select 'Green',2,3,'Vinny',1940 from dual union all
    select 'Green',2,4,'Omy',1945 from dual union all
    select 'Green',2,5,'Vijjy',1950 from dual union all
    select 'Green',3,6,'Vicky',1960 from dual union all
    select 'Green',3,7,'Varis',1965 from dual union all
    select 'Green',6,8,'Vshnu',1980 from dual union all
    select 'Green',6,9,'Dyna',1985 from dual union all
    select 'Green',8,10,'Mary',2000 from dual union all
    select 'Green',8,11,'Mac',2005 from dual union all
    select 'Green',7,12,'Garry',1985 from dual union all
    select 'Green',7,13,'Ganny',1990 from dual union all
    select 'Brown',null,14,'Joe',1950 from dual union all
    select 'Brown',14,15,'Jim',1970 from dual union all
    select 'Brown',14,16,'Joy',1975 from dual union all
    select 'Brown',14,17,'Jay',1980 from dual union all
    select 'Brown',16,18,'Jack',1995 from dual union all
    select 'Brown',18,19,'Jake',2010 from dual union all
    select 'Brown',18,20,'Jess',2012 from dual
    select family,
           root_name||' ('||to_char(root_born)||')' "(FA/MO)THER",
           children
      from (select family,
                   root_born,
                   root_name,
                   ltrim(sys_connect_by_path(person_name||' ('||to_char(born)||')',', '),', ') children
              from (select family,
                           connect_by_root(person_name) root_name,
                           connect_by_root(born) root_born,
                           person_name,
                           born,
                           row_number() over (partition by family,connect_by_root(person_name) order by born) rn
                      from family_tree
                     where level = 2
                    connect by prior person = ancestor
             where connect_by_isleaf = 1
             start with rn = 1
            connect by prior root_name = root_name
                   and prior family = family
                   and prior rn + 1 = rn
    order by family desc,root_born
    Regards
    Etbin

  • CONNECT BY PRIOR USING MULTIPLE TABLES RETURNS  AWKAWARD RESULTS.

    CREATE TABLE "JAM"."FTVORGN2"
       (    "FTVORGN_COAS_CODE" VARCHAR2(1 CHAR) NOT NULL ENABLE,
        "FTVORGN_ORGN_CODE" VARCHAR2(6 CHAR) NOT NULL ENABLE,
        "FTVORGN_EFF_DATE" DATE NOT NULL ENABLE,
        "FTVORGN_ACTIVITY_DATE" DATE NOT NULL ENABLE,
        "FTVORGN_USER_ID" VARCHAR2(30 CHAR) NOT NULL ENABLE,
        "FTVORGN_NCHG_DATE" DATE NOT NULL ENABLE,
        "FTVORGN_TERM_DATE" DATE,
        "FTVORGN_TITLE" VARCHAR2(35 CHAR) NOT NULL ENABLE,
        "FTVORGN_STATUS_IND" VARCHAR2(1 CHAR),
        "FTVORGN_ORGN_CODE_PRED" VARCHAR2(6 CHAR),
        "FTVORGN_DATA_ENTRY_IND" VARCHAR2(1 CHAR) NOT NULL ENABLE,
        "FTVORGN_VPDI_CODE" VARCHAR2(6 CHAR)
    I have a table like the above.
    I also have a table like the below.
    CREATE TABLE "JAM"."FORUSOR"
       (    "FORUSOR_USER_ID_ENTERED" VARCHAR2(30 CHAR) NOT NULL ENABLE,
        "FORUSOR_COAS_CODE" VARCHAR2(1 CHAR) NOT NULL ENABLE,
        "FORUSOR_ORGN_CODE" VARCHAR2(6 CHAR) NOT NULL ENABLE,
        "FORUSOR_ACCESS_IND" VARCHAR2(1 CHAR) NOT NULL ENABLE,
        "FORUSOR_ACTIVITY_DATE" DATE NOT NULL ENABLE,
        "FORUSOR_USER_ID" VARCHAR2(30 CHAR) NOT NULL ENABLE,
        "FORUSOR_WBUD_ACCESS_IND" VARCHAR2(1 CHAR) NOT NULL ENABLE,
        "FORUSOR_SURROGATE_ID" NUMBER(19,0),
        "FORUSOR_VERSION" NUMBER(19,0),
        "FORUSOR_DATA_ORIGIN" VARCHAR2(30 CHAR),
        "FORUSOR_VPDI_CODE" VARCHAR2(6 CHAR)
    REM INSERTING into FTVORGN2
    SET DEFINE OFF;
    Insert into FTVORGN2 (FTVORGN_COAS_CODE,FTVORGN_ORGN_CODE,FTVORGN_EFF_DATE,FTVORGN_ACTIVITY_DATE,FTVORGN_USER_ID,FTVORGN_NCHG_DATE,FTVORGN_TERM_DATE,FTVORGN_TITLE,FTVORGN_STATUS_IND,FTVORGN_ORGN_CODE_PRED,FTVORGN_DATA_ENTRY_IND,FTVORGN_VPDI_CODE) values ('D','01',to_date('01-OCT-88','DD-MON-RR'),to_date('19-MAR-97','DD-MON-RR'),'TRAIN01',to_date('31-DEC-99','DD-MON-RR'),null,'TOTAL UNIVERSITY','A',null,'N',null);
    Insert into FTVORGN2 (FTVORGN_COAS_CODE,FTVORGN_ORGN_CODE,FTVORGN_EFF_DATE,FTVORGN_ACTIVITY_DATE,FTVORGN_USER_ID,FTVORGN_NCHG_DATE,FTVORGN_TERM_DATE,FTVORGN_TITLE,FTVORGN_STATUS_IND,FTVORGN_ORGN_CODE_PRED,FTVORGN_DATA_ENTRY_IND,FTVORGN_VPDI_CODE) values ('D','1006',to_date('22-SEP-14','DD-MON-RR'),to_date('22-SEP-14','DD-MON-RR'),'MJ35',to_date('31-DEC-99','DD-MON-RR'),null,'Provost','A','01','N',null);
    Insert into FTVORGN2 (FTVORGN_COAS_CODE,FTVORGN_ORGN_CODE,FTVORGN_EFF_DATE,FTVORGN_ACTIVITY_DATE,FTVORGN_USER_ID,FTVORGN_NCHG_DATE,FTVORGN_TERM_DATE,FTVORGN_TITLE,FTVORGN_STATUS_IND,FTVORGN_ORGN_CODE_PRED,FTVORGN_DATA_ENTRY_IND,FTVORGN_VPDI_CODE) values ('D','2027',to_date('01-OCT-97','DD-MON-RR'),to_date('01-OCT-97','DD-MON-RR'),'DARDARMT',to_date('31-DEC-99','DD-MON-RR'),null,'Sch of Biomed Engr, Sci Health Sys','A','1006','N',null);
    Insert into FTVORGN2 (FTVORGN_COAS_CODE,FTVORGN_ORGN_CODE,FTVORGN_EFF_DATE,FTVORGN_ACTIVITY_DATE,FTVORGN_USER_ID,FTVORGN_NCHG_DATE,FTVORGN_TERM_DATE,FTVORGN_TITLE,FTVORGN_STATUS_IND,FTVORGN_ORGN_CODE_PRED,FTVORGN_DATA_ENTRY_IND,FTVORGN_VPDI_CODE) values ('D','2028',to_date('28-FEB-01','DD-MON-RR'),to_date('28-FEB-01','DD-MON-RR'),'JMOORE',to_date('31-DEC-99','DD-MON-RR'),null,'Sch of Envr Science, Engr Policy','A','1006','N',null);
    Insert into FTVORGN2 (FTVORGN_COAS_CODE,FTVORGN_ORGN_CODE,FTVORGN_EFF_DATE,FTVORGN_ACTIVITY_DATE,FTVORGN_USER_ID,FTVORGN_NCHG_DATE,FTVORGN_TERM_DATE,FTVORGN_TITLE,FTVORGN_STATUS_IND,FTVORGN_ORGN_CODE_PRED,FTVORGN_DATA_ENTRY_IND,FTVORGN_VPDI_CODE) values ('D','5275',to_date('01-OCT-97','DD-MON-RR'),to_date('02-JUL-99','DD-MON-RR'),'JMOORE',to_date('31-DEC-99','DD-MON-RR'),null,'Administration','A','1006','N',null);
    Insert into FTVORGN2 (FTVORGN_COAS_CODE,FTVORGN_ORGN_CODE,FTVORGN_EFF_DATE,FTVORGN_ACTIVITY_DATE,FTVORGN_USER_ID,FTVORGN_NCHG_DATE,FTVORGN_TERM_DATE,FTVORGN_TITLE,FTVORGN_STATUS_IND,FTVORGN_ORGN_CODE_PRED,FTVORGN_DATA_ENTRY_IND,FTVORGN_VPDI_CODE) values ('D','5325',to_date('01-OCT-97','DD-MON-RR'),to_date('13-JAN-00','DD-MON-RR'),'JMOORE',to_date('31-DEC-99','DD-MON-RR'),null,'Enrollment & Career Management','A','1006','N',null);
    Insert into FTVORGN2 (FTVORGN_COAS_CODE,FTVORGN_ORGN_CODE,FTVORGN_EFF_DATE,FTVORGN_ACTIVITY_DATE,FTVORGN_USER_ID,FTVORGN_NCHG_DATE,FTVORGN_TERM_DATE,FTVORGN_TITLE,FTVORGN_STATUS_IND,FTVORGN_ORGN_CODE_PRED,FTVORGN_DATA_ENTRY_IND,FTVORGN_VPDI_CODE) values ('D','5350',to_date('01-OCT-97','DD-MON-RR'),to_date('02-JUL-99','DD-MON-RR'),'JMOORE',to_date('31-DEC-99','DD-MON-RR'),null,'Office of Education','A','1006','N',null);
    Insert into FTVORGN2 (FTVORGN_COAS_CODE,FTVORGN_ORGN_CODE,FTVORGN_EFF_DATE,FTVORGN_ACTIVITY_DATE,FTVORGN_USER_ID,FTVORGN_NCHG_DATE,FTVORGN_TERM_DATE,FTVORGN_TITLE,FTVORGN_STATUS_IND,FTVORGN_ORGN_CODE_PRED,FTVORGN_DATA_ENTRY_IND,FTVORGN_VPDI_CODE) values ('D','5365',to_date('01-OCT-97','DD-MON-RR'),to_date('02-JUL-99','DD-MON-RR'),'JMOORE',to_date('31-DEC-99','DD-MON-RR'),null,'Library','A','1006','N',null);
    REM INSERTING into FORUSOR
    SET DEFINE OFF;
    Insert into FORUSOR (FORUSOR_USER_ID_ENTERED,FORUSOR_COAS_CODE,FORUSOR_ORGN_CODE,FORUSOR_ACCESS_IND,FORUSOR_ACTIVITY_DATE,FORUSOR_USER_ID,FORUSOR_WBUD_ACCESS_IND,FORUSOR_SURROGATE_ID,FORUSOR_VERSION,FORUSOR_DATA_ORIGIN,FORUSOR_VPDI_CODE) values ('jam337','D','1006','B',to_date('01-AUG-12','DD-MON-RR'),'P','N',null,null,null,null);
    Insert into FORUSOR (FORUSOR_USER_ID_ENTERED,FORUSOR_COAS_CODE,FORUSOR_ORGN_CODE,FORUSOR_ACCESS_IND,FORUSOR_ACTIVITY_DATE,FORUSOR_USER_ID,FORUSOR_WBUD_ACCESS_IND,FORUSOR_SURROGATE_ID,FORUSOR_VERSION,FORUSOR_DATA_ORIGIN,FORUSOR_VPDI_CODE) values ('jam337','D','1007','B',to_date('01-AUG-12','DD-MON-RR'),'P','N',null,null,null,null);
    Insert into FORUSOR (FORUSOR_USER_ID_ENTERED,FORUSOR_COAS_CODE,FORUSOR_ORGN_CODE,FORUSOR_ACCESS_IND,FORUSOR_ACTIVITY_DATE,FORUSOR_USER_ID,FORUSOR_WBUD_ACCESS_IND,FORUSOR_SURROGATE_ID,FORUSOR_VERSION,FORUSOR_DATA_ORIGIN,FORUSOR_VPDI_CODE) values ('jam337','D','1011','B',to_date('01-AUG-12','DD-MON-RR'),'P','N',null,null,null,null);
    Insert into FORUSOR (FORUSOR_USER_ID_ENTERED,FORUSOR_COAS_CODE,FORUSOR_ORGN_CODE,FORUSOR_ACCESS_IND,FORUSOR_ACTIVITY_DATE,FORUSOR_USER_ID,FORUSOR_WBUD_ACCESS_IND,FORUSOR_SURROGATE_ID,FORUSOR_VERSION,FORUSOR_DATA_ORIGIN,FORUSOR_VPDI_CODE) values ('jam337','D','1026','Q',to_date('30-JAN-08','DD-MON-RR'),'P','N',null,null,null,null);
    Insert into FORUSOR (FORUSOR_USER_ID_ENTERED,FORUSOR_COAS_CODE,FORUSOR_ORGN_CODE,FORUSOR_ACCESS_IND,FORUSOR_ACTIVITY_DATE,FORUSOR_USER_ID,FORUSOR_WBUD_ACCESS_IND,FORUSOR_SURROGATE_ID,FORUSOR_VERSION,FORUSOR_DATA_ORIGIN,FORUSOR_VPDI_CODE) values ('jam337','D','1100','Q',to_date('30-JAN-08','DD-MON-RR'),'P','N',null,null,null,null);
    the ftvorgn table is hierachical in nature, where the forusor table is not . The FORUSOR table holds the name and a hiearchy node from the FTVORGN TABLE within it.
    I have spent several hours trying to get a query to work. I just don't see  what my error is? if you follow the trail thus far you will notice that the FORUSOR table contains a value of '1006' in  the FORUSOR_ORGN_CODE  column. However everytime I run this query i get duplicate rows in return.
    SELECT FTVORGN_ORGN_CODE,
                 FTVORGN_DATA_ENTRY_IND,
                 FTVORGN_TITLE,
                 FTVORGN_STATUS_IND,
                 FTVORGN_ORGN_CODE_NSF,
                 FTVORGN_HIERARCHY_TABLE_IND,
                 LEVEL, FTVORGN_ORGN_CODE_PRED
         FROM    FTVORGN2, FORUSOR
         WHERE   FORUSOR.FORUSOR_USER_ID_ENTERED = 'jam337'
        CONNECT BY PRIOR FTVORGN_ORGN_CODE = FTVORGN_ORGN_CODE_PRED
                 AND   PRIOR FTVORGN_COAS_CODE = FTVORGN_COAS_CODE
                 AND   FTVORGN_EFF_DATE <= TO_DATE(sysdate)
                 AND   FTVORGN_NCHG_DATE > TO_DATE(sysdate)
      START WITH       FTVORGN_ORGN_CODE = FORUSOR_ORGN_CODE
                 AND   FTVORGN_COAS_CODE = 'D'
                 AND   FTVORGN_EFF_DATE <= TO_DATE(sysdate)
                 AND   FTVORGN_NCHG_DATE > TO_DATE(sysdate);
    I't trying to basically get all the predecessor notes for everynote on FORUSOR but i keep ending up with  duplicate rows.
    I should end up with something similar to this.
    sorry for the format of the results I'm not very good at formatting.
    "FTVORGN_ORGN_CODE"      
    "FTVORGN_DATA_ENTRY_IND" 
    "FTVORGN_STATUS_IND"     
    "LEVEL"                  
    "FTVORGN_ORGN_CODE_PRED"
    "1006"                   
    "N"                      
    "A"                      
    "1"                      
    "01"                    
    "2027"                   
    "N"                      
    "A"                      
    "2"                      
    "1006"                  
    "2028"                   
    "N"                      
    "A"                      
    "2"                      
    "1006"                  
    "5275"                   
    "N"                      
    "A"                      
    "2"                      
    "1006"                  
    "5325"                   
    "N"                      
    "A"                      
    "2"                      
    "1006"                  
    "5350"                   
    "N"                      
    "A"                      
    "2"                      
    "1006"                  
    "5365"                   
    "N"                      
    "A"                      
    "2"                      
    "1006"                  
    on column FORUSOR_ORGN_CODE in the FORUSOR table there is a node value that corresponds to a value on FTVORGN. However , that value could have a FTVORGN_ORGN_CODE_PRED which basically says I'm reporting to this value.
    if I basically run this query for a node you can see the hierachy.
    SELECT FTVORGN_ORGN_CODE,
                 FTVORGN_DATA_ENTRY_IND,
                 FTVORGN_STATUS_IND,
                 LEVEL, FTVORGN_ORGN_CODE_PRED
         FROM    FTVORGN2
      CONNECT BY PRIOR FTVORGN_ORGN_CODE = FTVORGN_ORGN_CODE_PRED
                 AND   PRIOR FTVORGN_COAS_CODE = FTVORGN_COAS_CODE
                 AND   FTVORGN_EFF_DATE <= TO_DATE(sysdate)
                 AND   FTVORGN_NCHG_DATE > TO_DATE(sysdate)
      START WITH       FTVORGN_ORGN_CODE = '1006'
                 AND   FTVORGN_COAS_CODE = 'D'
                 AND   FTVORGN_EFF_DATE <= TO_DATE(sysdate)
                 AND   FTVORGN_NCHG_DATE > TO_DATE(sysdate);
    I now need to pass the orgn code from forusor to this query to get all the ftvorgn_orgn_code that this user technically has reporting to him on FORUSOR.
    so for example user jma337 has org
    1006 in forusor
    when i run the query i should get
    jma337  2027
    jma337  2028
    jma337 5275 etc.
    Reason in because these are all predecessors of 1006 which in this case would essentially be our level 1.
    I need to do this all the FORUSOR_ORGN_CODE this user has recorded to him on FORUSOR.

    Switching to four digit years (to make the query work)
    with
    ftvorgn2 as
    (select 'D' ftvorgn_coas_code,
            '01' ftvorgn_orgn_code,
            to_date('01-OCT-1988','DD-MON-YYYY') ftvorgn_eff_date,
            to_date('19-MAR-1997','DD-MON-YYYY') ftvorgn_activity_date,
            'TRAIN01' ftvorgn_user_id,
            to_date('31-DEC-2099','DD-MON-YYYY') ftvorgn_nchg_date,
            null ftvorgn_term_date,
            'TOTAL UNIVERSITY' ftvorgn_title,
            'A' ftvorgn_status_ind,
            null ftvorgn_orgn_code_pred,
            'N' ftvorgn_data_entry_ind,
            null ftvorgn_vpdi_code
       from dual
    union all
    select 'D','1006',to_date('22-SEP-2014','DD-MON-YYYY'),to_date('22-SEP-2014','DD-MON-YYYY'),'MJ35',to_date('31-DEC-2099','DD-MON-YYYY'),null,'Provost','A','01','N',null from dual union all
    select 'D','2027',to_date('01-OCT-1997','DD-MON-YYYY'),to_date('01-OCT-1997','DD-MON-YYYY'),'DARDARMT',to_date('31-DEC-2099','DD-MON-YYYY'),null,'Sch of Biomed Engr, Sci Health Sys','A','1006','N',null from dual union all
    select 'D','2028',to_date('28-FEB-2001','DD-MON-YYYY'),to_date('28-FEB-2001','DD-MON-YYYY'),'JMOORE',to_date('31-DEC-2099','DD-MON-YYYY'),null,'Sch of Envr Science, Engr Policy','A','1006','N',null from dual union all
    select 'D','5275',to_date('01-OCT-1997','DD-MON-YYYY'),to_date('02-JUL-1999','DD-MON-YYYY'),'JMOORE',to_date('31-DEC-2099','DD-MON-YYYY'),null,'Administration','A','1006','N',null from dual union all
    select 'D','5325',to_date('01-OCT-1997','DD-MON-YYYY'),to_date('13-JAN-2000','DD-MON-YYYY'),'JMOORE',to_date('31-DEC-2099','DD-MON-YYYY'),null,'Enrollment & Career Management','A','1006','N',null from dual union all
    select 'D','5350',to_date('01-OCT-1997','DD-MON-YYYY'),to_date('02-JUL-1999','DD-MON-YYYY'),'JMOORE',to_date('31-DEC-2099','DD-MON-YYYY'),null,'Office of Education','A','1006','N',null from dual union all
    select 'D','5365',to_date('01-OCT-1997','DD-MON-YYYY'),to_date('02-JUL-1999','DD-MON-YYYY'),'JMOORE',to_date('31-DEC-2099','DD-MON-YYYY'),null,'Library','A','1006','N',null from dual
    forusor as
    (select 'jam337' forusor_user_id_entered,
            'D' forusor_coas_code,
            '1006' forusor_orgn_code,
            'B' forusor_access_ind,
            to_date('01-AUG-12','DD-MON-RR') forusor_activity_date,
            'P' forusor_user_id,
            'N' forusor_wbud_access_ind,
            null forusor_surrogate_id,
            null forusor_version,
            null forusor_data_origin,
            null forusor_vpdi_code
        from dual
    union all
    select 'jam337','D','1007','B',to_date('01-AUG-2012','DD-MON-YYYY'),'P','N',null,null,null,null from dual union all
    select 'jam337','D','1011','B',to_date('01-AUG-2012','DD-MON-YYYY'),'P','N',null,null,null,null from dual union all
    select 'jam337','D','1026','Q',to_date('30-JAN-2008','DD-MON-YYYY'),'P','N',null,null,null,null from dual union all
    select 'jam337','D','1100','Q',to_date('30-JAN-2008','DD-MON-YYYY'),'P','N',null,null,null,null from dual
    select ftvorgn_orgn_code, 
           ftvorgn_data_entry_ind, 
           ftvorgn_title, 
           ftvorgn_status_ind, 
        -- ftvorgn_orgn_code_nsf, 
        -- ftvorgn_hierarchy_table_ind, 
           level,
           ftvorgn_orgn_code_pred 
      from ftvorgn2
    start with ftvorgn_orgn_code in (select forusor_orgn_code 
                                        from forusor
                                       where forusor_user_id_entered = 'jam337'
                                     --  and forusor_coas_code = 'D'
    connect by prior ftvorgn_orgn_code = ftvorgn_orgn_code_pred
           and ftvorgn_eff_date <= sysdate
           and ftvorgn_nchg_date > sysdate
    FTVORGN_ORGN_CODE
    FTVORGN_DATA_ENTRY_IND
    FTVORGN_TITLE
    FTVORGN_STATUS_IND
    LEVEL
    FTVORGN_ORGN_CODE_PRED
    1006
    N
    Provost
    A
    1
    01
    2027
    N
    Sch of Biomed Engr, Sci Health Sys
    A
    2
    1006
    2028
    N
    Sch of Envr Science, Engr Policy
    A
    2
    1006
    5275
    N
    Administration
    A
    2
    1006
    5325
    N
    Enrollment & Career Management
    A
    2
    1006
    5350
    N
    Office of Education
    A
    2
    1006
    5365
    N
    Library
    A
    2
    1006
    Regards
    Etbin

  • Query tuning for query using connect by prior

    I have written following query to fetch the data. The query is written in this format because there are multiple rows, which make one recrd and we need to bring that record into one row.
    For one CAT(commented here), this query takes around 4 minutes and fetches 6900 records but when it runs for 3 CAT, it takes 17 mins.
    I want to tune this as this has to run for 350 CAT values.
    It is doing FTS on the main table. I tried to use different hints like PARALLEL, APPEND (in insert) but nothing worked.
    The cost of the query is 51.
    Any help/suggestions will be appreciated.
    SELECT DISTINCT MIN(SEQ) SEQ,
    PT, APP, IT, LR, QT,CD, M_A_FLAG,
    STRAGG(REM) REM, -- aggregates the data from different columns to one which is parent
    CAT
    FROM (WITH R AS (SELECT CAT, SEQ, PT, M_A_FLAG, IT, LR,QT,CD, REM, APP
    FROM table1
    WHERE REC = '36' AND M_A_FLAG = '1'
    --AND CAT = '11113')
    SELECT CAT, SEQ,
    CONNECT_BY_ROOT PT AS PT,
    CONNECT_BY_ROOT APP AS APPL,
    M_A_FLAG,
    CONNECT_BY_ROOT IT AS IT,
    CONNECT_BY_ROOT LR AS LR,
    CONNECT_BY_ROOT QT AS QT,
    CONNECT_BY_ROOT CD AS CD,
    REM
    FROM R A
    START WITH PT IS NOT NULL
    CONNECT BY PRIOR SEQ + 1 = SEQ
    AND PRIOR CAT = CAT
    AND PT IS NULL)
    GROUP BY PT, APP, IT,LR, QT, CD, M_A_FLAG, CAT
    ORDER BY SEQ;
    Thanks.
    Edited by: user2544469 on Feb 11, 2011 1:12 AM

    The following threads detail the approach and information required.
    Please gather relevant info and post back.
    How to post a SQL tuning request - HOW TO: Post a SQL statement tuning request - template posting
    When your query takes too long - When your query takes too long ...

  • Can anyone please help with a Connect by PRIOR sql?

    Hi,
    I am not so well versed in Oracle analytic functions and am having trouble with a sql.
    Oracle Version: 9.2.0.1.0
    I have a tree table storing heirarchies upto 4 levels.
    create table FAMILY_TREE
    TREE_ID NUMBER not null,
    PARENT_ID NUMBER,
    NAME VARCHAR2(100)
    I know that using a CONNECT BY PRIOR, I can find out who the previous ancestar is.
    select
    f.tree_id TreeId,
    f.parent_id ParentId,
    f.Name Name
    from family_tree f
    connect by
    prior f.tree_id = f.parent_id
    start with f.parent_id is null
    I need to display all the ancestars in a single line (in different columns), which is where I am stumped.
    I need the output, in different columns as :
    Joe Jack Harry Rick Ned
    Bascially, I need to display in a single row, all the ancestars.
    I tried to use joins but it was very very slow due to the fact that I had to perform multiple joins.
    Can anyone please point me in the right direction?
    Data:
    insert into FAMILY_TREE (TREE_ID, PARENT_ID, NAME)
    values (1, null, 'Joe');
    insert into FAMILY_TREE (TREE_ID, PARENT_ID, NAME)
    values (2, 1, 'Jack');
    insert into FAMILY_TREE (TREE_ID, PARENT_ID, NAME)
    values (3, 2, 'Harry');
    insert into FAMILY_TREE (TREE_ID, PARENT_ID, NAME)
    values (4, 3, 'Rick');
    insert into FAMILY_TREE (TREE_ID, PARENT_ID, NAME)
    values (5, 4, 'Ned');

    This may give you a start
    SQL> ed
    Wrote file afiedt.buf
      1  select f.tree_id TreeId,f.parent_id ParentId,
      2          trim(',' from sys_connect_by_path(f.Name,',')) name
      3  from family_tree f
      4  connect by
      5  prior f.tree_id = f.parent_id
      6* start with f.parent_id is null
    SQL> /
        TREEID   PARENTID NAME
             1            Joe
             2          1 Joe,Jack
             3          2 Joe,Jack,Harry
             4          3 Joe,Jack,Harry,Rick
             5          4 Joe,Jack,Harry,Rick,Ned
    Message was edited by:
            jeneesh
    Forgot to refresh..                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Result to be in multiple columns instead of one

    Hi,
    i have used the below sql :
    select parent_id, max(sys_connect_by_path(name,'^')) History
    from (select parent_id, name, row_number() over (partition by parent_id order by name) rn
    from notes )
    start with rn = 1
    connect by prior rn = rn-1
    and prior parent_id = parent_id
    group by parent_id
    order by parent_id
    this gets me the 'HISTORY' row returned in a single column. Problem is if i have 5 HISTORY notes, they all appear in same column with delimiter ^.
    Please help to modify query as to get History as multiple columns instead of 1
    Below is example of sample data returned , NOTE: history could contain any amount of rows.
    ID     HISTORY
    1     ^TT updates requested^TT updates requested^Update on TT #104836
    2     ^Call back actioned^Delivery Update^Internation Dialing ^TT Follow up (147023)
    3     ^Queried poor signal strength
    Idea case would be :
    ID     HISTORY HISTORY1 HISTORY2
    1     TT updates requested TT updates requested Update on TT #104836

    Hi,
    You might want to leave the results as one long string, but just add some spacing.
    Right now you're using
    sys_connect_by_path(name,'^')and getting output like
    1 ^TT updates requested^TT updates requested^Update on TT #104836
    2 ^Call back actioned^Delivery Update^Internation Dialing ^TT Follow up (147023)
    3 ^Queried poor signal strengthwhich is as hard to read as an OTN posting that doesn't use \ tags.  Naturally you're not going to insult your uses by asking them to read something like that.
    If you use this instead:REPLACE ( sys_connect_by_path ( RPAD (name, 32)
                   ,'^'
         , '^'
    then the output will look like this:TT updates requested          TT updates requested          Update on TT #104836
    Call back actioned          Delivery Update               Internation Dialing           TT Follow up (147023)
    Queried poor signal strength
    See this thread:
    Re: Report count and sum from many rows into many columns
    for various ways to deal with problems like this.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Drill-down to multiple columns at same time

    Hello,
    Is it possible to simultaneously drill down to multiple columns on the same level with one click? I have several attributes that the user will want to see together at all times, so I want to be able to drill from level1 to level2a,2b, and 2c with one click.
    Thanks,
    Elliot

    This drilling down to all the levels may not be available with the OBIEE drill level based hierarchy feature OOTB but as an alternative you can try this at you DB level to create a hierarchy within you data using START WITH and CONNECT BY PRIOR to generate the parent->child levels hierarchy within the view instead of creating multiple hierarchical columns.
    Or may be you can try to create separate columns in a table for each hierarchy level. That table could either be in the database or be a logical one in the repository. For example:
    Level 1 Level 2 Level 3 Description
    1 2A 3A
    1 2A 3B
    1 2B 3A
    1 2B 3B
    etc
    You then create separate reports for each level, so one report has only level1 in it for this dimension, another report has levels 1 an 2 and a third report has levels 1, 2 and 3 etc.
    In each report you put an action link on the levels' cells so that if you click on them you drill up or down by displaying a new report with either less or more level columns.
    Hope this helps. Pls mark if it does.
    Thanks,
    SVS

  • Merge multiple columns into single column?

    Hi,
    I need to execute queries dynamically and return the values. I need to fetch the values of the queries in single column only by concatenating the multiple columns. I cannot use PL/SQL in my scenario.
    is there any way to execute a query and the result will be fetched in single column (values of multiple columns needs to be concatenated)?
    Thanks,
    Raja.

    hi,
    do you mean this??
      1* select EMPNO||' '||ENAME||' '||JOB||' '||MGR||' '||HIREDATE||' '||SAL||' '||COMM||' '||DEPTNO||
    SQL> /
    MULTIPLE_COL
    100 JDF DIR  05-SEP-09 200 1000 10
    7497 MILLER CLERK 7782 23-JAN-82 25000 195 35
    7566 JONES MANAGER 7839 02-APR-81 3175 446.25 20
    7654 RAR SALESMAN 7698 28-SEP-81 1450 1587.5 30
    7698 BLAKE MANAGER 7839 01-MAY-81 3050 427.5 30
    7782 CLARK MANAGER 7839 09-JUN-81 2650 367.5 10
    7788 SCOTT ANALYST 7566 09-DEC-82 3200 450 20
    7839 KING PRESIDENT  17-NOV-81 5200 8250 10
    7844 TURNER SALESMAN 7698 08-SEP-81 1700 225 30
    7876 ADAMS CLERK 7788 12-JAN-83 1300 165 20
    7900 JAMES CLERK 7698 03-DEC-81 1150 85.5 30 [email protected]
    MULTIPLE_COL
    7902 FORD ANALYST 7566 03-DEC-81 3200 450 20
    8000 KINGBABA PRESIDENT  17-NOV-81 5200 8250 10
    8001 TURNER RAV SALESMAN 8000 08-SEP-81 1700 450 30
    1001 KITTU DOR  05-SEP-09 1200 100 40
    15 rows selected.Or
    Mean this??
    SQL> ed
    Wrote file afiedt.buf
      1  With T As
      2     ( Select Level col1 From dual Connect By Level<=10
      3     )
      4     Select Max(SYS_CONNECT_BY_PATH(COL1||',',' ')) Multi_col
      5       From
      6     ( Select COL1, Lag(COL1) Over (Order By COL1) As Lag
      7             From   T  )
      8      Start With Lag Is Null
      9        Connect By
    10*    Prior col1 = LAG
    SQL> /
    MULTI_COL
    1, 2, 3, 4, 5, 6, 7, 8, 9, 10,Edited by: user291283 on Sep 8, 2009 10:10 PM

  • How to get the root node for a child using connect by prior

    Hi,
    I searched at many places to do this but not able to get the exact o/p sp posting my question here.
    I have a table with parent_id and child_id columns. The levels of this parent_child can be many but my aim is to find the ultimate parent ( dont know the right term)
    like if I have a child_node= xyz and its parent= pqr and its parents=lmn which might be ultimate parent which doesnt have any further parent.
    So if i start with child_code= "xyz" then i should get the parent as "lmn" and not the immediate parent "pqr".
    Please help.
    Thanks,
    Aashish

    To find the Parent on emp table:
    select empno,ename,level
    from emp
    where level=3
    start with empno=7934
    connect by  empno= prior mgrTo find the Child on emp table:
    select empno,ename,level
    from emp
    where level=1
    start with empno=7934
    connect by prior empno=  mgrBut you need to know the level or position to specify the level of parent or child. But there are some other possible options available if we can know the requirement properly.
    Edited by: Vasista on Jan 11, 2011 2:27 AM
    Edited by: Vasista on Jan 11, 2011 2:30 AM

  • How to insert from one table to another (multiple columns to single column)

    I want to insert data from table1 into table2 and the data looks in 3 columns as below
    Table1     
    RepNm ObjNm DbNm
    123     abc def
    456     def xyz
    789     123 456
    and the data in table2 should be display as
    Table 2
    ObjNm
    123
    456
    789
    abc
    def
    xyz
    the dupes should get eliminated and only the distinct values should be inserted into a single column in table2 from multiple columns in table1

    How do you want to handle nulls? If there is a null in any value of a column, do you want to insert it?
    Then,
    WITH T
         AS (SELECT LEVEL colnum
               FROM DUAL
             CONNECT BY LEVEL <= 3)
    SELECT DECODE (colnum,  1, RepNm,  2, ObjNm,  3, DbNm) as ObjNm
      FROM table1, T;if you dont want to insert nulls then,
    WITH T
         AS (SELECT LEVEL colnum
               FROM DUAL
             CONNECT BY LEVEL <= 3)
    SELECT DECODE (colnum,  1, RepNm,  2, ObjNm,  3, DbNm) AS ObjNm
      FROM table1, T
    WHERE DECODE (colnum,  1, RepNm,  2, ObjNm,  3, DbNm) = DECODE (colnum,  1, RepNm,  2, ObjNm,  3, DbNm)G.

  • Connect by prior in Oracle 11g

    I am upgrading an application from 9i to 11g and I've been told that the connect by prior sql is broken. While I am waiting for the example and the error message, is 11g pickier about looping than 9i was? Can someone point me to some documentation on 10 or 11 changes to hierarchical queries?
    Thanks in advance.
    Jim

    Hi, Jim,
    user509659 wrote:
    I am upgrading an application from 9i to 11g and I've been told that the connect by prior sql is broken. What do you mean? Post a link, or at least a more complete description of the problem.
    While I am waiting for the example and the error message, is 11g pickier about looping than 9i was? Can someone point me to some documentation on 10 or 11 changes to hierarchical queries?There were a lot of improvements to CONNECT BY in Oracle 10, including CONNECT BY NOCYCLE (for working with loops), the CONNECT_BY_ROOT operator, and pseudo-columns CONNECT_BY_ISCYCLE and CONNECT_BY_ISLEAF. Look them up in the SQL Language manual for your version.
    I don't know of any improvements or changes to CONNECT BY in Oracle 11.
    Oracle 11.2 has recursive WITH clauses, that can do everything that CONNECT BY does, and more. Some things in 11.2 are simpler and more efficient using CONNECT BY, others are better done using recursive WITH clauses.
    Everything that CONNECT BY did in earlier versions, it does in Oracle 11, as well. If you have a CONNECT BY query that works in Oracle 9, it should work in Oracle 11, without any changes, though there might be better ways to get the same results in Oracle 11.
    Whenever you have a question, post youir code, and whatever is necessary to run it, including CREATE TABLE and INSERT statments for a little sample data. Post the results you want from that sample data, and an explanation of how you get those results from that data.
    Always say which version of Oracle you're using, e.g. 11.2.0.2.0. The difference between 11.1 and 11.2 may be very significant in this case.
    See the forum FAQ {message:id=9360002}

  • Connect by prior problem with order by

    Hi,
    I and using connect by prior within a query on Oracle 8 and would like to order the results within the parent levels.
    All the documentation that I have read shows that in Oracle 9i there is an option to say order siblings by which looks like what I need, but this does not work on Oracle 8.
    Can anyone tell me how I can order the children within the parents without changing the tree structure?
    I have also tried SYS_CONNECT_BY_PATH and I just get an error saying that it is an invalid column name,

    Karen, see here for a dicussion on how to order the siblings in a pre-9i environment:
    http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:9212348049

  • Connect by prior by speific order problem.

    Oracle: 10.2.0.4
    I have a table containing events backup.
    i want to list the hierarchy within that backup oreder by the time_stamp for all levels.
    create table BCK_EVENTS
      bck_backup_id           NUMBER(9) default 0 not null,
      event_id                   NUMBER(15) default 0 not null,
      event_name              NVARCHAR2(100) default ' ' not null
      time_stamp               NUMBER(9) default 0 not null,
      parent_event            NUMBER(15) default 0 not null,
    add constraint BCK_EVENTS_PK primary key (BCK_EVENT_ID, EVENT_ID); // event_id is not unique can be under one or more backup id'sthis is not a tree with one root, there is more than one event in the root level (level 1).
    example:
    Event Name      Time         level   <- time is numeric but for easier reading.
    *Event A          10:00         1
       *Event C        10:30         2
         *Event B      11:17         3
    *Event H          12:10         1
         *Event J       12:10         2
         *Event M      12:21         2
    *Event Z          15:33         1
       *Event R        16:56          2
        *Event M      16:57          3
       *Event G        20:20         2What i tried was :
    select  lpad( '*', level*2 ) || event_id,event_name,time_stamp,parent_event,level from bck_events
         where bck_event_id=100031
         start with parent_event is null
        connect by prior event_id = parent_eventand there are two problems with it.
    1. it's not ordered even when i added an Index (parent_event,time_stamp) and try to hint it.
    2. it returns loads of multiple rows.
    hope it's clear enough. I thank for any help.
    Edited by: 973065 on Nov 25, 2012 8:04 AM
    Edited by: 973065 on Nov 25, 2012 9:23 AM
    Edited by: 973065 on Nov 25, 2012 9:29 AM
    Edited by: 973065 on Nov 25, 2012 9:31 AM

    Hi,
    973065 wrote:
    Oracle: 10.2
    I have a table containing events backup.
    i want to list the hierarchy within that backup oreder by the time_stamp for all levels.
    create table BCK_EVENTS
    bck_backup_id           NUMBER(9) default 0 not null,
    event_id                   NUMBER(15) default 0 not null,
    event_name              NVARCHAR2(100) default ' ' not null
    time_stamp               NUMBER(9) default 0 not null,
    parent_event            NUMBER(15) default 0 not null,
    Thanks for posting the version number and the CREATE TABLE statement. Don't forget to post INSERT statements for your sample data.
    add constraint BCK_EVENTS_PK primary key (BCK_EVENT_ID, EVENT_ID); // event_id is not unique can be under one or more backup id's
    this is not a tree with one root, there is more than one event in the root level (level 1).Is it a forest, that is, a set of trees?
    example:
    Event Name      Time         level   <- time is numeric but for easier reading.
    *Event A          10:00         1
    *Event C        10:30         2
    *Event B      11:17         3
    *Event H          12:10         1
    *Event J       12:10         2
    *Event M      12:21         2
    *Event Z          15:33         1
    *Event R        16:56          2
    *Event M      16:57          3
    *Event G        20:20         2
    That seems to be a forest, that is, every row has 0 or 1 parent, and no row is its own ancestor.
    What i tried was :
    select lpad( '*', level*2 ) || event_id,event_name,time_stamp,parent_event,level from bck_events
    where bck_event_id=100031
    start with parent_event is null
    connect by prior event_id = parent_event
    and there are two problems with it.
    1. it's not ordered even when i added an Index (parent_event,time_stamp) and try to hint it.Depending on your data, you may just need to add
    ORDER SIBLINGS BY  time_stampat the end, after the CONNECT BY clause.
    If you need rows sorted by time_stamp under their roots, but otherwise without regard to the hierarchy, then use CONNECT_BY_ROOT.
    2. it returns loads of multiple rows.Again, it depends on your data. I'll bet you need something more in the CONNECT BY clause, but I can't tell what without some sample data and an exxplanation of how you gett the results you posted from that data. The fact that bck_event_id is part of the primary key makes me suspect that maybe bck_event_id needs to be somewhere in the CONNECT BY clause, but that's just a wild guess.
    hope it's clear enough. I thank for any help.As mentioned before, see the forum FAQ {message:id=9360002}

  • CONNECT BY PRIOR statement issue

    Hi,
    I'm using the below select query to build a relationship b/w ID & parent_id, but HANA studio is throwing a syntax error. I don't see a problem around the syntax. Please throw some light's here.
    SELECT * FROM "SIVA_TEST"."Core_Competency" START with  "Competency_ID"=1
    CONNECT BY PRIOR "Competency_ID" = "Parent_Competency_ID"   ;
    Error:
    Could not execute 'SELECT * FROM "SIVA_TEST"."Core_Competency" START WITH "Competency_ID"='1' CONNECT BY PRIOR ...' in 170 ms 563 µs .
    SAP DBTech JDBC: [257] (at 46): sql syntax error: incorrect syntax near "START": line 2 col 1 (at pos 46)
    Table struct:
    create column table "SIVA_TEST"."Core_Competency"("Competency_ID" integer,
    "Competency_Name" varchar(200),
    "Competency_description" varchar(1000),
    "Parent_Competency_ID" integer,
    "start_date" date,
    primary key("Competency_ID"));
    Thanks,
    Siva.

    Insert statement for the corresponding table..
    INSERT INTO "SIVA_TEST"."Core_Competency" VALUES (1,'value 1',null,null,'2013-12-02');
    INSERT INTO "SIVA_TEST"."Core_Competency" VALUES (2,'value 2',null,1,'2013-07-31');
    INSERT INTO "SIVA_TEST"."Core_Competency" VALUES (3,'value 3',null,1,'2013-02-01');
    INSERT INTO "SIVA_TEST"."Core_Competency" VALUES (4,'value 4',null,2,'2013-06-24');
    INSERT INTO "SIVA_TEST"."Core_Competency" VALUES (5,'value 6',null,2,'2013-04-09');
    INSERT INTO "SIVA_TEST"."Core_Competency" VALUES (6,'value 7',null,3,'2013-09-12');
    INSERT INTO "SIVA_TEST"."Core_Competency" VALUES (7,'value 8',null,3,'2013-08-09');
    INSERT INTO "SIVA_TEST"."Core_Competency" VALUES (8,'value 9',null,7,'2013-04-09');
    INSERT INTO "SIVA_TEST"."Core_Competency" VALUES (9,'value 10',null,7,'2013-12-09');
    INSERT INTO "SIVA_TEST"."Core_Competency" VALUES (10,'value 11',null,4,'2013-09-08');
    INSERT INTO "SIVA_TEST"."Core_Competency" VALUES (11,'value 12',null,4,'2013-10-10');

  • CONNECT BY PRIOR question

    Hi, I have following problem
    Table TMP contains following data
    ID PID
    1
    2 1
    3 2
    select t.id
    from tmp t
    where level=(select max(level)
    from tmp t2
    connect by prior t2.pid=t2.id
    start with t2.id=&ID)
    connect by prior t.pid=t.id
    start with t.id=&ID
    Select returns 1 when ID=3
    Is there a way to write select so that it returns value for first node
    and value of ID used in select?
    Something like
    select value_of_ID
    ,t.id
    from tmp t
    start with t.id=&ID
    so I could use group by on first column (group by value_of_ID)
    Following select would not satisfy:
    select &ID
    ,t.id
    from tmp t
    start with t.id=&ID

    I would suggest something more straightforward:
    select :startnode, id
      from tmp
    where pid is null
    start with id = :startnode
    connect by prior pid = id;The WHERE clause will limit the result to just the top level - no need for a subquery or aggregate functions.

Maybe you are looking for

  • Problem with Enable scalable feature of XSLT processor

    Hi Gurus, I'm using BI Publisher 10.1.3.4.1. I've having a report, when running in a specific sequence (i.e. after running with XML dataset 1 then dataset 2), will yield an error. Here is the log I got in the xdo.log. [061411_110902953][][EXCEPTION]

  • BAM Portal is only displaying one day of aggregations

    Has anyone else seen this behaviour and better still how did you resolve it? See http://connectedpawns.wordpress.com/2014/09/25/bam-is-displaying-only-one-day-of-aggregations/ We implemented a BAM solution using BizTalk Server 2013 and Standard SQL s

  • BP Internal Reconciliation problem

    Hi, I am working with B1 2007A PL41. When I click BP-> Internal Reconciliation-> Reconciliation, select BP and click reconcile. Then for  ARIN dated 1.August I change the amount to part amount and select an incoming payment dated 13.August - here too

  • LR 1.1 with CS2?

    In the readme file with LR 1.1 it says: "Adobe applications must be updated with the Camera Raw 4.1 plug-in order to ensure compatibility with Lightroom 1.1 develop module settings. The following products will support the Camera Raw 4.1 plug-in: Phot

  • EA4500 router not opening ports even in DMZ

    I have a EA4500 router running the following firmware: http://puu.sh/4l2Hb.jpg I want to forward the following ports to host a game server: http://puu.sh/4l2Jb.png In case you are wondering device ip# is correct and my computer has a static ip: http: