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

Similar Messages

  • 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

  • Hi all i am trying to use a Connect by prior clause

    Hi all,
    In my connect by prior clause i have a query. I want to pass the values to the query from my outer query. Can this be done in Oracle.Can any help me in this.Also Pasting my query for your reference
    SELECT rct2.trx_number
         , rctl2.customer_trx_line_id
         , fifs.flex_value_set_id
         , gcc.code_combination_id
         , ffvc.child_flex_value
         , ffvc.parent_flex_value
         , gcc.segment4
         , ffvc.description
         , ffvc.lvl
    FROM   ra_customer_trx_all rct2
          ,ra_customer_trx_lines_all rctl2
          ,ra_cust_trx_line_gl_dist_all rctlgd
          ,gl_code_combinations gcc
          , (SELECT     ffvv.flex_value_set_id
                      , ffvv.flex_value child_flex_value
                      , LEVEL lvl, ffvv.parent_flex_value
                      , ffvv.description
                   FROM fnd_flex_value_children_v ffvv
                  WHERE 1 = 1
                  START WITH  ffvv.flex_value = (SELECT 
          gcc.segment4
      FROM ra_customer_trx_all rct1,
           ra_customer_trx_lines_all rctl1,
           ra_cust_trx_line_gl_dist_all rctlgd,
           gl_code_combinations gcc
    WHERE rct1.customer_trx_id=rctl1.customer_trx_id
    AND rctl1.customer_trx_line_id=rctlgd.customer_trx_line_id
    AND  rct1.customer_trx_id=rctlgd.customer_trx_id
    AND rctlgd.account_class = 'REV'
    AND rctlgd.code_combination_id=gcc.code_combination_id
    AND rct1.trx_number            = :trx_number--Want to pass  rct2.trx_number here which is coming from outer query
    AND rctla.customer_trx_line_id = :trx_line_id)--Want to pass rctl2.customer_trx_line_id here which is coming from outer query
             CONNECT BY PRIOR ffvv.parent_flex_value = ffvv.flex_value  ) ffvc
          ,fnd_flex_value_sets s
          ,fnd_id_flex_segments fifs
          ,gl_ledgers l
    WHERE rct2.customer_trx_id           = rctl2.customer_trx_id
       AND rctl2.customer_trx_line_id   = rctlgd.customer_trx_line_id
       AND rct2.customer_trx_id          = rctlgd.customer_trx_id
       AND rctlgd.code_combination_id   = gcc.code_combination_id
       AND fifs.flex_value_set_id       = ffvc.flex_value_set_id
       AND fifs.application_id          = 101
       AND fifs.flex_value_set_id       = s.flex_value_set_id
       AND fifs.application_column_name = 'SEGMENT4'
       AND fifs.id_flex_code            = 'GL#'
       AND l.chart_of_accounts_id       = fifs.id_flex_num
       AND l.ledger_id                  = rct2.set_of_books_id
       AND rctlgd.account_class         = 'REV'
       AND rctl2.customer_trx_line_id   = :trx_line_id --Pass Trx id
       AND rct2.trx_number              = :trx_number  --Pass trx number

    Hello.
    "I created a function and added the above query to the function and passed the values  as parameters at both places"
    Well, this is not the best idea, because adding a function to your SQL will add many context switches (depending on the volume of your data) and may badly affect the CBO to choose not optimal execution plan. That's why it is better to avoid it if possible. Actually, I found no problem in using correlated subquery in the start with clause:
    with
        t1 as (
            select 1 as id, null as pid from dual
            union all
            select 2, 1 from dual
            union all
            select 3, 1 from dual
            union all
            select 5, 2 from dual
        t2 as (
            select 1 as t2id from dual
            union all
            select 2 as t2id from dual
    select lpad(' ', 2 * (level-1)) || t1.id as id
        , level
        , case when t1.id = connect_by_root t1.id then 'ROOT' else null end as ROOT
    from t1
    start with t1.id = (select t2.t2id from t2 where t2.t2id = t1.id)
    connect by prior t1.id = t1.pid
    order siblings by t1.id;
    ID
    LEVEL
    ROOT
    1
    1
    ROOT
      2
    2
        5
    3
      3
    2
    2
    1
    ROOT
      5
    2
    But, as Frank Kulash reasonably said, depending on the volume that you work with, it may probably be better to do the join before the connect by like this for example:
    with
        t1 as (
            select 1 as id, null as pid from dual
            union all
            select 2, 1 from dual
            union all
            select 3, 1 from dual
            union all
            select 5, 2 from dual
        t2 as (
            select 1 as t2id from dual
            union all
            select 2 as t2id from dual
    select lpad(' ', 2 * (level-1)) || t1.id as id
        , level
        , case when t1.id = connect_by_root t1.id then 'ROOT' else null end as ROOT
    from t1 left join t2 on t1.id = t2.t2id
    start with t2.t2id is not null
    connect by prior t1.id = t1.pid
    order siblings by t1.id
    ID
    LEVEL
    ROOT
    1
    1
    ROOT
      2
    2
        5
    3
      3
    2
    2
    1
    ROOT
      5
    2

  • Clarification regarding understanding of ORACLE CONNECT BY PRIOR Clause

    Dear All,
    I am trying to understand ORACLE CONNECT BY CLAUSE and I wrote a query to verify my understanding.
    I wrote the below two queries.
    select level, lpad('*',2*(level -1),'*') ||ename t_ename, sys_connect_by_path(ename,'/') enames, empno, mgr from emp
    --where empno =empno
    start with empno=7654
    --start with mgr is null
    connect by prior empno = mgr;
    LEVEL T_ENAME ENAMES EMPNO MGR
    1 MARTIN /MARTIN 7654 7698
    Explanation: Here Start with EMPNO=7654 Means, the root node is 7654. Connect BY PRIOR EMPNO=MGR Means--> For the empno=7654 are there any persons under him. IE. Mgr with 7654.
    select level, lpad('*',2*(level -1),'*') ||ename t_ename, sys_connect_by_path(ename,'/') enames, empno, mgr from emp
    --where empno =empno
    start with empno=7698
    --start with mgr is null
    connect by prior empno = mgr
    LEVEL T_ENAME ENAMES EMPNO MGR
    1 BLAKE /BLAKE 7698 7839
    2 **ALLEN /BLAKE/ALLEN 7499 7698
    2 **WARD /BLAKE/WARD 7521 7698
    2 **MARTIN /BLAKE/MARTIN 7654 7698
    2 **TURNER /BLAKE/TURNER 7844 7698
    2 **JAMES /BLAKE/JAMES 7900 7698
    Explanation: Here Start with EMPNO=7698 Means, the root node is 7698. Connect BY PRIOR EMPNO=MGR Means--> For the empno=7698 are there any persons under him. IE. Mgr with 7698.
    IS MY UNDERSTANDING OF CONNECT BY PRIOR IS CORRECT?
    Please correct me if I am wrong.
    Thanks,
    MK.

    Yes, you're right
    Regards,
    Sayan M.

  • 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 in Oracle 8i question

    Need help with building tree-structured query in Oracle 8i (Forms 6i front end if it matters).
    Sample structure and data:
    CREATE TABLE table_list
    my_code NUMBER,
    my_level NUMBER,
    my_description VARCHAR2(60)
    CREATE TABLE table_content
    my_code NUMBER,
    term_code NUMBER,
    term_category VARCHAR2(5)
    INSERT into table_list values (101, 1, 'building');
    INSERT into table_list values (102, 2, 'flat');
    INSERT into table_list values (103, 3, 'living room');
    INSERT into table_list values (104, 3, 'bedroom');
    INSERT into table_list values (105, 3, 'bathroom');
    commit;
    INSERT into table_content values (101, 102, 'Sub');
    INSERT into table_content values (102, 103, 'Sub');
    INSERT into table_content values (102, 104, 'Sub');
    INSERT into table_content values (102, 105, 'Sub');
    commit;
    Need to display data in the following order:
    101 'building' --level one
         102 'flat' --level two
              105 'bathroom' --level three
              104 'bedroom' --level three
              103 'living room' --level three
    *(note alphabetical order in level three)*
    Looks like Oracle 8i does not support table joins for CONNECT BY PRIOR. Please advise!

    And you are correct, it does not display level 1. Do
    you think this is this a database structure problem
    or it could be corrected via query modification?No and yes. It's not a "structure" problem, its a data problem (as I explained above). You always fix data problems by making queries overly complex (hint, hint, I don't suggest doing it this way).
    select tl.my_level, tl.my_description , LPAD(' ',3*(my_level-1)) || substr(tl.my_description, 1, 30) description
    from table_list tl,
    (select term_Code from table_content
    start with my_code in (select my_code from table_list where my_level=1)
    connect by prior term_code = my_code
    ) x
    where x.term_code = tl.my_code
    union all
    select my_level, my_description
    from table_list
    where my_level = 1
    order by 1, 2
    better to add a row to table_content with my_code=null, term_code=101.
    otherwise you'll be pulling stupid nonsense like above with every query from here on out.

  • Checking multiple conditions in a standard if clause

    Greetings all,
    I have a PO Template that I want to print a Note at the bottom of each Line (inside the table having the group_by) when the CANCEL_FLAG=Y. But I want to print one Note if the QUANTITY>0 and a different Note if the QUANTITY=0. My current statement looks like this:
    <?if:(CANCEL_FLAG=’Y’) and (QUANTITY>0)?><<<< PO Line LINE# was Partially Cancelled on: 01-JAN-2007 >>>><?end if?>
    <?if:(CANCEL_FLAG=’Y’) and (QUANTITY=0)?><<<< PO Line LINE# was Cancelled on: 01-JAN-2007 >>>><?end if?>
    It works fine, printing only the first Note when the QUANTITY>0. However, when the QUANTITY=0 it prints BOTH Notes. Is there a better way of doing this? I have verified in the second case that the QUANTITY is actually 0 and not NULL.
    Any suggestions would be appreciated.
    Regards,
    Donn Shumway

    I did find the problem and corrected it by specifying the current level of the element.
    <?if:(./CANCEL_FLAG=’Y’) and (./QUANTITY>0)?><<<< PO Line LINE# was Partially Cancelled on: 01-JAN-2007 >>>><?end if?>
    <?if:(./CANCEL_FLAG=’Y’) and (./QUANTITY=0)?><<<< PO Line LINE# was Cancelled on: 01-JAN-2007 >>>><?end if?>
    Thanks,
    Donn

  • Connect BY, Prior, Start clause

    I want to understand how does the Connect BY, Prior, Start clause work, i mean the concept.
    Please explain with an example.
    I hope, my question is clear. Please help in solving the doubt as it is urgent.
    Regards.

    Here is the simple example you can find in a dept first traversal fashion the records come in mgr-emp hirarchy
    SQL>SELECT * FROM EMP
      2  START WITH MGR IS NULL
      3  CONNECT BY PRIOR EMPNO = MGR;
         EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTN
          7839 KING       PRESIDENT            17-NOV-81       5000                    1
          7566 JONES      MANAGER         7839 02-APR-81       2975                    2
          7788 SCOTT      ANALYST         7566 19-APR-87       3000                    2
          7876 ADAMS      CLERK           7788 23-MAY-87       1100                    2
          7902 FORD       ANALYST         7566 03-DEC-81       3000                    2
          7369 SMITH      CLERK           7902 17-DEC-80        800                    2
          7698 BLAKE      MANAGER         7839 01-MAY-81       2850                    3
          7499 ALLEN      SALESMAN        7698 20-FEB-81       1600                    3
          7521 WARD       SALESMAN        7698 22-FEB-81       1250                    3
          7654 MARTIN     SALESMAN        7698 28-SEP-81       1250                    3
          7844 TURNER     SALESMAN        7698 08-SEP-81       1500                    3
          7900 JAMES      CLERK           7698 03-DEC-81        950                    3
          7782 CLARK      MANAGER         7839 09-JUN-81       2450                    1
          7934 MILLER     CLERK           7782 23-JAN-82       1300                    1

  • Connect by prior (hierarchical query)

    Hi All,
    Some1 asked me a question which goes like this:
    Source
    emp_no dep_no
    110 10
    110 20
    110 30
    110 40
    120 10
    130 10
    130 20
    write a query to achieve the following output from the above source
    emp_no dept_no
    110 10203040
    120 10
    130 1020
    Now I have come across solutions with 'connect by prior' clauses but I am nt able to understand how oracle is producing that result , Could someone point me to a good article or text that can explain this concept very thoroughly( I have searched on google and got to see many articles but I couldnt able to understand it since these articles were not explaining everything)
    Regards
    Rahul

    You can try this:
    SQL> ed
    Wrote file afiedt.buf
      1  SELECT deptno,MAX(TRIM(SUBSTR(SYS_CONNECT_BY_PATH(empid,','),2)))
      2         KEEP(DENSE_RANK LAST ORDER BY deptno) FROM
      3  (SELECT deptno,empid,ROW_NUMBER() OVER(PARTITION BY deptno ORDER BY deptno) curr,
      4                       ROW_NUMBER() OVER(PARTITION BY deptno ORDER BY deptno) - 1 prev
      5  FROM emp)
      6  CONNECT BY PRIOR curr = prev
      7  AND deptno = PRIOR deptno
      8  START WITH curr = 1
      9* group by deptno
    SQL> /
        DEPTNO MAX(TRIM(SUBSTR(SYS_CONNECT_BY_PATH(EMPID,','),2)))KEEP(DENSE_RANKLASTORDERBYDEPTNO)
            10 1,2,3,4
            20 5,6,7
    SQL> select deptno,empid from emp;
        DEPTNO      EMPID
            10          1
            10          2
            10          3
            10          4
            20          5
            20          6
            20          7
    7 rows selected.
    SQL>

  • Advice on connect by prior

    Hi Consultants,
    i have to report the account balance user the parents 511000, 520000, 530000, 540000, 550000, 570000.
    i need to put condition in my query to get only for above accounts.
    For exmaple :
    512011 is child to 512000 and 512000 is child to 511000.
    for i need to develop a query to find root parent for child account.
    i developed below query
    select parent_flex_value from
    ( SELECT fchi.parent_flex_value,fval.flex_value FROM APPS.FND_FLEX_VALUE_SETS FSET,
    APPS.FND_FLEX_VALUES FVAL
    ,apps.FND_FLEX_VALUE_CHILDREN_V FCHI
    WHERE FSET.FLEX_VALUE_SET_NAME LIKE 'Account%'
    AND FSET.flex_value_set_id = FVAL.flex_value_set_id
    --AND FVAL.flex_value = '510000'
    AND FSET.flex_value_set_id = FCHI.flex_value_set_id
    AND FVAL.FLEX_VALUE = FCHI.flex_value) f1 ,APPS.FND_FLEX_VALUES F2
    where f2.flex_value = f1.flex_value
    Start with f1.flex_value = '512000'
    CONNECT BY PRIOR f1.flex_value = F2.FLEX_VALUE
    order by level
    it is giving error like ORA-01436: CONNECT BY loop in user data
    Please advise me or corret the query if there is any incorrect
    THanks in advance.
    Ashok

    Hello,
    I think there is something wrong with your query.
    You have the condition
    where f2.flex_value = f1.flex_valueand then you connect by prior clause :
    CONNECT BY PRIOR f1.flex_value = F2.FLEX_VALUEIt is on the same columns, so for the connect by prior clause, f1.flex_value is always equal to F2.FLEX_VALUE and that is why it is looping.
    To to a correct recursive query, your should have a table with a column that represents the child identifier and a column that represents the parent identifier. and the CONNECT BY PRIOR clause do the link between child and parent.
    Hope this will help.
    Regards,
    Sylvie

  • Help me in understand connect By Prior

    Hi ,
    please help me in understand connect By Prior
    I did a sample example , but unale to follow , please explain
    How did it understand that KING shuld be displaed first .
    On wht basis the results are shown here ?
    SELECT empno,
    ename,
    job,
    mgr,
    hiredate,
    level
    FROM   emp
    START WITH mgr IS NULL
    CONNECT BY PRIOR empno = mgr
    7839     KING PRESIDENT      17-Nov-81     1
    7566     JONES MANAGER 7839     2-Apr-81     2
    7788     SCOTT ANALYST 7566     19-Apr-87     3
    7876     ADAMS CLERK 7788     23-May-87     4
    7902     FORD ANALYST 7566     3-Dec-81     3
    7369     SMITH CLERK 7902     17-Dec-80     4
    7698     BLAKE MANAGER 7839     1-May-81     2
    7499     ALLEN SALESMAN 7698     20-Feb-81     3
    7521     WARD SALESMAN 7698     22-Feb-81     3
    7654     MARTIN SALESMAN 7698     28-Sep-81     3
    7844     TURNER SALESMAN 7698     8-Sep-81     3
    7900     JAMES CLERK 7698     3-Dec-81     3
    7782     CLARK MANAGER 7839     9-Jun-81     2
    7934     MILLER CLERK 7782     23-Jan-82     3

    Hi,
    user10503747 wrote:
    Hi ,
    please help me in understand connect By Prior
    I did a sample example , but unale to follow , please explain
    How did it understand that KING shuld be displaed first .
    On wht basis the results are shown here ?In a CONNECT BY query (without an ORDER BY clause), if x is an ancestor of y (that is, if x is the parent of y, or x is the parent of the parent of y, and so on), then y will be displayed after x, but before any other row that does not have x as its ancestor. (That is also the order in which ROWNUM will be assigned. This applies only to the query in which CONNECT BY is done. If you use the results set as a sub-query, the super query may cause the results to be re-arranged. An ORDER BY clause always takes precedence.)
    In a CONNECT BY query, every row in the result set either:
    (a) satisfies the START WITH condition, or
    (b) is a descendant of some row in (a); that is, some row that satifies the START WITH condition is its ancestor.
    Since ancestors always come before their descendants, the first row in the result set must be a row that satisfied the START WITH condition. In your example, the row with ename='KING' was the only row that satisfied the condition "START WITH mgr IS NULL", and all the other rows are its descendants, so the row with ename='KING' must come first, as APC said.

  • How can I pass multiple condition in where clause with the join table?

    Hi:
    I need to collect several inputs at run time, and query the record according to the input.
    How can I pass multiple conditions in where clause with the join table?
    Thanks in advance for any help.
    Regards,
    TD

    If you are using SQL-Plus or Reports you can use lexical parameters like:
    SELECT * FROM emp &condition;
    When you run the query it will ask for value of condition and you can enter what every you want. Here is a really fun query:
    SELECT &columns FROM &tables &condition;
    But if you are using Forms. Then you have to change the condition by SET_BLOCK_PROPERTY.
    Best of luck!

  • 'CONNECT BY PRIOR..START WITH'  clause  Usage

    Hi All,
    Could you please let me know the usage of 'connect by prior...start with' clause.
    I only know that it helps for hierarchial retrival,but not aware of details.
    Can someone provide the use with example for the same.
    On searching on the net,I have seen numerous examples but none of them could explain it properly and everywhere the same SCOTT/TIGER schemas EMP and MGR table's example is given which is not enough explanatory.
    Thanks in advance...
    Aashish S.

    suppose u need to get all employees in a company in a hirerchical manner
    ie presdent then mgrs
    then employeess reporting to them
    this can be done using connect by prior and start by
    select empname from emp
    connect by prior empno=mgrno
    start with mgrno is null

  • Connect By prior with condition

    i have a table employee with following fields
    EMPLOYEEID, MANAGERID, ISPOOL
    i have following query
    select employeeid MID , level LVL from employee connect by prior employeeid=managerid and working=-1 start with employeeid =1
    i need to change it so that i will return me the tree for all employees who have ispool='Y'
    mangers of ispool='Y' may may have ispool='N'
    Thanks in Advance

    closed ...
    requirement changed..

  • 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

Maybe you are looking for

  • How do I create an interactive pdf form my clients can actually use?

    In the new CS6 Indesign (which is very easy to use to make forms) I've gone through all the steps to make a beautiful form whose buttons, text fields, and hyperlinks all work (great!) but now I've stumbled across one VITAL problem: the submit form bu

  • Unable to find Form.UDFFormUID property in B1 SDK 8.81

    Hello Experts, I'm quite new to SAP SDK and I have a little question for you: I know there should be a UDFFormUID property in the Form object of UI API, from B1 SDK 2007 and 8.8 also, as it is said for example in this thread: Form UDFFormUID new prop

  • BBM not working with WiFi

    Hello friends..I recently bought Z10. With WiFi I am able to use FB, Whatsapp, BB App World But unable to use BBM messenger..Please suggest a solution..I have updated the OS to 10.2

  • How do I bend an image?

    Hey all - I searched and searched. How do I bend an image? I want to give it a 3d feel. If you take a piece of paper and make it do a U shape on a table (Touching the left and right edge only). And look down on it I want that effect. That's the best

  • IBM Storage Manager ibmawt.so java error

    I need to use the IBM DS Storage Manager found here: http://www-947.ibm.com/systems/support/ … nd=5000028 I can install fine on 32bit arch notebook, but on my x86_64 workstation the installer window never pops up becuase I get this error below. me ~/