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.

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

  • Help needed with CONNECT BY PRIOR

    I need to display salesrep-manager hierarchy. I'm using the following SQL and am sure I'm doing something wrong somewhere, but just can't pinpoint. Any help is greatly appreciated.
    <pre>
    SELECT sf.source_name salesrep
    ,mgr.full_name manager
    ,level
    FROM as_salesforce_v sf
    ,per_all_assignments_f pass
    ,per_all_people_f mgr
    WHERE sf.role_name = 'Sales Representative'
    AND SYSDATE BETWEEN nvl(sf.start_date_active, SYSDATE) AND
    nvl(sf.end_date_active, SYSDATE)
    AND SYSDATE BETWEEN nvl(pass.effective_start_date, SYSDATE) AND
    nvl(pass.effective_end_date, SYSDATE)
    AND SYSDATE BETWEEN nvl(mgr.effective_start_date, SYSDATE) AND
    nvl(mgr.effective_end_date, SYSDATE)
    CONNECT BY PRIOR mgr.person_id = pass.supervisor_id
    START WITH pass.person_id = sf.employee_person_id;
    </pre>
    TIA
    Alka.
    Forgot to mention, the SQL takes forever to run.
    Message was edited by:
    user498444

    as_salesforce_v view stores the salesrep name (as specified by the condition sf.role_name = 'Sales Representative'). This view also has rows for managers of salesreps as that's how Oracle Sales app allows the users to access the app. This table stores employee id in column employee_person_id.
    per_all_assignments_f table stores the assignments for all the employees (including salesreps and that's why condition START WITH pass.person_id = sf.employee_person_id). It also stores the employee id for the manager (column supervisor_id).
    per_all_people_f has all the employee records (including manager records) and the column person_id is the employee id (condition pass.supervisor_id = mgr.person_id).
    Hope this explanation is helpful.

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

    Hi all,
    In Connect By Prior, How can i avoid, if some parent dont have child means, it should not come in the results.......
    Regards,
    Fame

    A "parent" without a child will not show up as a parent, but it may show up as a child.
    When that happens, CONNECT_BY_ISLEAF will be 1.
    So, filter on CONNECT_BY_ISLEAF = 0.select empno, ename, job, mgr from scott.emp
    where connect_by_isleaf = 0
    start with mgr is null
    connect by mgr = prior empno;
         EMPNO ENAME      JOB              MGR
          7839 KING       PRESIDENT           
          7566 JONES      MANAGER         7839
          7788 SCOTT      ANALYST         7566
          7902 FORD       ANALYST         7566
          7698 BLAKE      MANAGER         7839
          7782 CLARK      MANAGER         7839Edited by: Stew Ashton on Jan 17, 2013 1:34 PM

  • Connect by prior need help

    Hi all,
    Im having two tables like as following,
    menu_roles : Table Name
    MENU_ID     ROLE           REGION          SEGMENT     PERSON_ID      ENABLED_FLAG
    13     -          -          -          31766     Y
    27     Account Manager     -          -     -                Y
    29     Account Manager     -          -     -          
    1     Account Manager     -          -          -               Y
    2     Account Manager     SOUTH          -          -               Y
    2     COO          EAST          Corporate     31547               Y
    12     -          -          '          31766          Y
    Menu_master : Table Name
    MENU_ID     MENU_NAME     MENU_PARENT_ID     RANK      MENU_LEVEL     ENABLED_FLAG     DELETE_FLAG
    1     T_Folder1          1     0     Y      N
    2     T_Folder2          2 0 Y     N
    3     T_SubItem1.1     1 2     1     Y     N
    4     T_SubItem1.2     1     1     1     Y      N
    5     T_SubItem1.1.1     3          2     Y     N
    6     T_SubItem1.1.2     3     1 2     Y     N
    7     T_SubItem1.1.1.1     5     1     3     Y     Y
    7     T_SubItem2.1     2          1     Y     N
    i need the result like the following
    MENU_ID     MENU_NAME     MENU_PARENT_ID     RANK     MENU_LEVEL
    1     T_Folder1               1     0
    4     T_SubItem1.2          1     1     1
    8     T_SubItem1.2.1          4     2     2
    3     T_SubItem1.1          1     2     1
    6     T_SubItem1.1.2          3     1      2
    5     T_SubItem1.1.1          3          2
    Im using the query like as
    pergrpid := 791.
    WITH T AS
    (select mas.menu_id,
    mas.menu_name,
    mas.url,
    mas.apex_page_no,
    mas.menu_parent_id,
    mas.rank,
    mas.menu_level
    from sfa_menu_master mas
    where mas.enabled_flag = 'Y'
    and nvl(mas.delete_flag, 'N') = 'N'
    connect by prior mas.menu_id = mas.menu_parent_id
    start with menu_id in
    (select menu_id
    from sfa_menu_roles rol
    where (rol.role in
    (select max(role)
    from sfa_per_groups grp
    where grp.per_group_id = pergrpid) or
    rol.region in
    (select region
    from sfa_per_groups grp
    where grp.per_group_id = pergrpid) or rol.region = null or
    rol.person_id = null))
    order siblings by rank)
    select * from t;
    but i want to check role , region ,segment , personid,
    if i give role,region, segment mean i want to check three conditions
    if i give only role and region mean want to check that 2 conditions only
    if i give role alone mean i have to check 1 conditions alone
    if i give personid mean i have to check personid
    awaiting for the reply.
    Thanks in Advance,
    839083 .

    A "parent" without a child will not show up as a parent, but it may show up as a child.
    When that happens, CONNECT_BY_ISLEAF will be 1.
    So, filter on CONNECT_BY_ISLEAF = 0.select empno, ename, job, mgr from scott.emp
    where connect_by_isleaf = 0
    start with mgr is null
    connect by mgr = prior empno;
         EMPNO ENAME      JOB              MGR
          7839 KING       PRESIDENT           
          7566 JONES      MANAGER         7839
          7788 SCOTT      ANALYST         7566
          7902 FORD       ANALYST         7566
          7698 BLAKE      MANAGER         7839
          7782 CLARK      MANAGER         7839Edited by: Stew Ashton on Jan 17, 2013 1:34 PM

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

  • Help regarding CONNECT BY PRIOR AND LEVEL

    Hi
    I need to retreive all the employees that are at the least level under a particular employee. Assume basic emp table.
    I have been using CONNECT BY PRIOR
    select mgr,empno,ename, level from emp
    start with empno=7839
    connect by prior empno=mgrOUTPUT:
    MGR     EMPNO     ENAME     LEVEL
         7839     KING     1
    7839     7566     JONES     2
    7566     7788     SCOTT     3
    7788     7876     ADAMS     4
    7566     7902     FORD     3
    7902     7369     SMITH     4
    7839     7698     BLAKE     2
    7698     7499     ALLEN     3
    7698     7521     WARD     3
    7698     7654     MARTIN     3
    7698     7844     TURNER     3
    7698     7900     JAMES     3
    7839     7782     CLARK     2
    7782     7934     MILLER     3The Output i require should be
    MGR     EMPNO     ENAME     LEVEL
    7788     7876     ADAMS     4
    7902     7369     SMITH     4
    7698     7499     ALLEN     3
    7698     7521     WARD     3
    7698     7654     MARTIN     3
    7698     7844     TURNER     3
    7698     7900     JAMES     3
    7782     7934     MILLER     3Also if i change the empno then i need to get only the employees under that employee only.
    Thanks in Advance,
    G.Vamsi Krishna

    oracle_for_dude wrote:
    can you explain what is this query doing
    SQL> select  mgr,empno,ename, level
    2  from    emp
    3  where   level  > 2
    4  start with  empno = 7566
    5  connect by  prior empno = mgr;
    MGR      EMPNO ENAME           LEVEL
    7788       7876 ADAMS               3
    7902       7369 SMITH               37566 in scott.emp table is employee_id of JONES, It's displaying the selected columns for all the employees in the sub-tree starting with Jones, not including Jones (who is at LEVEL=1) and the people who report directly to Jones (LEVEL=2).
    >
    >
    Thanks in advance

  • Help with 'connect by prior' statement

    I've got a quoting report that is sporadically ordering incorrectly and I've traced the source down to a 'connect by prior' statement. Can I get an explanation of what the statement is doing so I can figure out how to change it to get the desired results?
    select rownum config_rownum, quote_line_id,related_quote_line_id rlid, level
    from aso_line_relationships
    where relationship_type_code = 'CONFIG'
    connect by prior related_quote_line_id = quote_line_idsample output for the line_ids for one quote:
    CONFIG_ROWNUM     QUOTE_LINE_ID     RLID     LEVEL
    1          7438          7439     2
    2          7440          7441     2
    3          7430          7431     2
    4          7432          7433     2
    5          7432          7434     2
    6          7432          7435     2
    7          7436          7437     2
    8          7442          7443     2
    9          7442          7444     2
    10          7442          7445     2
    11          7442          7446     2
    12          7442          7447     2
    13          7442          7448     2
    14          7442          7449     2
    15          7450          7451     2
    16          7452          7453     2
    17          7452          7454     2
    18          7452          7455     2
    19          7456          7457     2
    20          7456          7458     2
    21          7456          7459     2
    22          7460          7461     2
    23          7460          7462     2
    24          7463          7464     2
    25          7430          7431     1
    26          7432          7433     1
    27          7432          7434     1
    28          7432          7435     1
    29          7436          7437     1
    30          7438          7439     1
    31          7440          7441     1
    32          7442          7443     1
    33          7442          7444     1
    34          7442          7445     1
    35          7442          7446     1
    36          7442          7447     1
    37          7442          7448     1
    38          7442          7449     1
    39          7450          7451     1
    40          7452          7453     1
    41          7452          7454     1
    42          7452          7455     1
    43          7456          7457     1
    44          7456          7458     1
    45          7456          7459     1
    46          7460          7461     1
    47          7460          7462     1
    48          7463          7464     1 The correct ordering can be seen by running this statement:
    select rownum config_rownum, quote_line_id,related_quote_line_id rlid
    from aso_line_relationships
    where relationship_type_code = 'CONFIG' and quote_line_id between 7430 and 7464
    CONFIG_ROWNUM     QUOTE_LINE_ID     RLID
    1          7430          7431
    2          7432          7433
    3          7432          7434
    4          7432          7435
    5          7436          7437
    6          7438          7439
    7          7440          7441
    8          7442          7443
    9          7442          7444
    10          7442          7445
    11          7442          7446
    12          7442          7447
    13          7442          7448
    14          7442          7449
    15          7450          7451
    16          7452          7453
    17          7452          7454
    18          7452          7455
    19          7456          7457
    20          7456          7458
    21          7456          7459
    22          7460          7461
    23          7460          7462
    24          7463          7464I tried to substitute the simple query above for the 'connect by prior' query in the report but failed because something in the report is expecting input from the 'connect by prior' statement. So eliminating the statement is not a choice.

    "connect by prior " is for for hierarchical queries which is for data has parent-children relationship, and ususlly its' result is used to populate tree-like data result. and order by is NOT recommend since it will destroy the hierarchical order.
    you could use "order by sibiling" if you would like to order inside the same level of data

  • Need help: CONNECT by PRIOR query in ora10g

    Hi All,
    Recently we have migrated the DB from 9i to 10g.
    we used to have many rule based queries in 9i
    and all are changed based on 10g.
    All the queries that have CONNECT BY PRIOR
    conditions seems to behave in wrong manner.
    ( same query in 9i,fetches less number of records where as 10g there were many
    rows displayed eventhough it was not selected in where clause.- as per business logic )
    After changing the below parameter setting , the problem was solved.
    can you tell wts the below setting would do? by doing so , ur again making 10g
    to behave like 9i so that full benefit of 10g is not used ?
    Alter session set “_optimizer_connect_by_cost_based”=false

    Hi, try this:
    WITH t AS (
    SELECT 100 AS node_id, cast(NULL AS NUMBER) AS parent_node_id FROM dual UNION ALL
    SELECT 101 AS node_id, 100 AS parent_node_id FROM dual UNION ALL
    SELECT 102 AS node_id, 100 AS parent_node_id FROM dual UNION ALL
    SELECT 1021 AS node_id, 102 AS parent_node_id FROM dual UNION ALL
    SELECT 1022 AS node_id, 102 AS parent_node_id FROM dual UNION ALL
    SELECT 10221 AS node_id, 1022 AS parent_node_id FROM dual UNION ALL
    SELECT 10222 AS node_id, 1022 AS parent_node_id FROM dual
    SELECT DISTINCT CONNECT_BY_ROOT parent_node_id AS ID, node_id AS id1
    FROM t
    CONNECT BY t.node_id = PRIOR parent_node_id
    START WITH parent_node_id = 1022
    ORDER BY 1, 2;

  • Help needed in understanding the concept of hierarchical queries

    I really need help in this matter. I have a flafile containing about 4000 rows. It is from my supplier, it's structure is as follows:
    create table Flatfile
    (Pgroup varchar2(30),
    Pclass varchar2(30),
    Manufacturer varchar2(30),
    Article varchar2(30),
    Price Number(6,2));
    Insert into Flatfile Values
    ('Application Software','Database Software','Oracle','Oracle 10G',115);
    Insert into Flatfile Values
    ('Application Software','Database Software','Microsoft','MS SQL Server 2000',200);
    Insert into Flatfile Values
    ('Application Software','Spreadsheet Software','Microsoft','Excel',100);
    Insert into Flatfile Values
    ('Monitor','15"','Acer','Acer 15"" TFT superscreen',199);
    Insert into Flatfile Values
    ('Monitor','15"','Sony','Sony R1500 flat',225);
    Insert into Flatfile Values
    ('Monitor','17"','Philips','Philips Flatscreen',250);
    Insert into Flatfile Values
    ('Monitor','19"','Viewsonic','Viewsonic PLasma Monitor',275);
    Insert into Flatfile Values
    ('Processor','AMD','AMD','FX-55',600);
    Insert into Flatfile Values
    ('Processor','Intel','Intel','P4 3 GHZ',399);
    My goal is to make a hierarchical query with the start with and connect by clauses. From what I have read is that I need to normalize the data of the flatfile.
    How do I achieve a table which I can query so that the query will represent the hierarchy that exists. Namely
    Pgroup
    ++Pclasse
    Application Software
    ++Database Software
    ++Spreadsheet Software
    So a 2-level hierarchy. I'd like to understand this simple concept first. I built on the knowledge that I gain. So the questions are:
    1.What do I need to do to make the table so that I can use a hierarchical query on it?
    2. How should the query syntax be?
    3. Is it also possible to get the data in the hierarchical query sorted asec?
    I would only like to use the simple structures of the start with and connect by clauses first. I've read there are some new additions to 10G. The problem with the examples used by the tutorials is that the tables are already made so that they are suitable for hierarchical queries. I hope to understand it by this example. And take it a step further.
    Sincerely,
    Pete

    Primarily hierarchy query serves to process tree-like structures which RDBMS simulates using through parent-child relation, often in a single table (see famoust
    EMP table where employee can have the manager who is an employee at the same time).
    In your case it could look like:
    SQL> select pgroup, pclass from flatfile;
    PGROUP                         PCLASS
    Application Software           Database Software
    Application Software           Database Software
    Application Software           Spreadsheet Software
    Monitor                        15"
    Monitor                        15"
    Monitor                        17"
    Monitor                        19"
    Processor                      AMD
    Processor                      Intel
                                   Application Software
                                   Monitor
                                   Processor
    12 rows selected.
    SQL> select decode(level,1,pclass,'  ' || pclass), Manufacturer from flatfile
      2  start with pgroup is null
      3  connect by prior pclass = pgroup
      4  /
    DECODE(LEVEL,1,PCLASS,''||PCLASS MANUFACTURER
    Application Software
      Database Software              Oracle
      Database Software              Microsoft
      Spreadsheet Software           Microsoft
    Monitor
      15"                            Acer
      15"                            Sony
      17"                            Philips
      19"                            Viewsonic
    Processor
      AMD                            AMD
      Intel                          Intel
    12 rows selected.The hierarchy syntax is described completely in the documentation including
    LEVEL and PRIOR keywords.
    As for the ordering question you can use siblings ordering:
    SQL> select decode(level,1,pclass,'  ' || pclass), Manufacturer from flatfile
      2  start with pgroup is null
      3  connect by prior pclass = pgroup
      4  order siblings by 1 desc
      5  /
    DECODE(LEVEL,1,PCLASS,''||PCLASS MANUFACTURER
    Processor
      Intel                          Intel
      AMD                            AMD
    Monitor
      19"                            Viewsonic
      17"                            Philips
      15"                            Acer
      15"                            Sony
    Application Software
      Spreadsheet Software           Microsoft
      Database Software              Oracle
      Database Software              Microsoft
    12 rows selected.Rgds.

  • 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

  • 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

  • SQL with connect by prior running for a long time

    Hi,
    We are using Oracle 10g. Below is a cursor sql which is having performance issues. The pAccountid is being passed from the output of a different cursor. But this cursor sql is running for a long time. Could you please help me in tuning this sql. I believe the subquery with connect by prior is causing the trouble.
    The TRXNS is a huge table which is not partitioned. The query is forced to use the index on the accountid of the TRXNS table.
    The accountlink table has 20,000 records and the TRXNStrack table has 10,000 records in total.
    This sql executes for 200,000 pAccountids and runs for more than 8 hours.
    SELECT /*+ INDEX(T TRXNS_ACCOUNTID_NIDX) */ AL.FROMACCOUNTID oldaccountid ,
                                    A.ACCOUNTNUM  oldaccountnum,
                                   T.TRXNSID,
                                   T.TRXNSTYPEID,
                                   T.DESCRIPTION ,
                                   T.postdt,
                                   T.TRXNSAMT
                        FROM
                        ACCOUNTLINK AL,
                        TRXNS T,
                        ACCOUNT A
                       WHERE AL.TOACCOUNTID IN
                                                             (SELECT TOACCOUNTID FROM ACCOUNTLINK START WITH TOACCOUNTID = pAccountid
                                                                                                                         CONNECT BY PRIOR FROMACCOUNTID  = TOACCOUNTID)
                            AND AL.FROMACCOUNTID = T.ACCOUNTID
                            AND A.ACCOUNTID = AL.FROMACCOUNTID
    AND NOT EXISTS (select 1 from TRXNStrack trck where trck.TRXNSid = t.TRXNSid AND TRXNSTrackReasonid = 1)
                            AND T.postdt > A.CLOSEDATE
                            AND T.postdt >= sysdate-2
                            AND T.postdt <= sysdate;
    Create script for trxn table:
    CREATE TABLE SP.TRXNS
      TRXNSID      NUMBER(15) CONSTRAINT "BIN$rpIQEeyLDfbgRAAUT4DEnQ==$0" NOT NULL,
      ACCOUNTID    NUMBER(15) CONSTRAINT "BIN$rpIQEeyMDfbgRAAUT4DEnQ==$0" NOT NULL,
      STATEMENTID  NUMBER(15),
      TRXNSTYPEID  NUMBER(15),
      DESCRIPTION  VARCHAR2(80 BYTE),
      postdt     DATE,
      TRXNSAMT     NUMBER(12,2),
      TRXNSREQID   NUMBER(15),
      LASTUPDATE   DATE,
      SOURCEID     NUMBER(15),
      HIDE         VARCHAR2(1 BYTE)
    TABLESPACE SO_TRXN_DATA
    RESULT_CACHE (MODE DEFAULT)
    PCTUSED    40
    PCTFREE    10
    INITRXNS   2
    MAXTRXNS   255
    STORAGE    (
                INITIAL          50M
                NEXT             1M
                MINEXTENTS       1
                MAXEXTENTS       UNLIMITED
                PCTINCREASE      0
                FREELISTS        8
                FREELIST GROUPS  1
                BUFFER_POOL      DEFAULT
                FLASH_CACHE      DEFAULT
                CELL_FLASH_CACHE DEFAULT
    LOGGING
    NOCOMPRESS
    NOCACHE
    NOPARALLEL
    MONITORING;
    CREATE INDEX SP.TRXNS_ACCOUNTID_NIDX ON SP.TRXNS
    (ACCOUNTID, postdt)
    LOGGING
    TABLESPACE SO_TRXN_INDEX
    PCTFREE    10
    INITRXNS   2
    MAXTRXNS   255
    STORAGE    (
                INITIAL          64K
                NEXT             1M
                MINEXTENTS       1
                MAXEXTENTS       UNLIMITED
                PCTINCREASE      0
                FREELISTS        1
                FREELIST GROUPS  1
                BUFFER_POOL      DEFAULT
                FLASH_CACHE      DEFAULT
                CELL_FLASH_CACHE DEFAULT
    NOPARALLEL;
    below is the executing plan for this sql taken from toad :
    PLAN_ID
    TIMESTAMP
    OPERATION
    OPTIONS
    OBJECT_OWNER
    OBJECT_NAME
    OBJECT_ALIAS
    OBJECT_INSTANCE
    OBJECT_TYPE
    OPTIMIZER
    SEARCH_COLUMNS
    ID
    PARENT_ID
    DEPTH
    POSITION
    COST
    CARDINALITY
    BYTES
    CPU_COST
    IO_COST
    TEMP_SPACE
    ACCESS_PREDICATES
    FILTER_PREDICATES
    PROJECTION
    TIME
    QBLOCK_NAME
    1121
    9/10/2013 3:30
    FILTER
    1
    0
    1
    1
    NOT EXISTS (SELECT 0 FROM "TRXNSTRACK" "TRCK" WHERE "TRXNSTRACKREASONID"=1 AND "TRCK"."TRXNSID"=:B1)
    AL."FROMACCOUNTID"[NUMBER,22], "T"."TRXNSID"[NUMBER,22], "T"."TRXNSTYPEID"[NUMBER,22], "T"."DESCRIPTION"[VARCHAR2,80], "T"."POSTDT"[DATE,7], "T"."TRXNSAMT"[NUMBER,22], "A"."ACCOUNTNUM"[VARCHAR2,19]
    SEL$5DA710D3
    1121
    9/10/2013 3:30
    FILTER
    2
    1
    2
    1
    SYSDATE@!-2<=SYSDATE@!
    AL."FROMACCOUNTID"[NUMBER,22], "T"."TRXNSID"[NUMBER,22], "T"."TRXNSTYPEID"[NUMBER,22], "T"."DESCRIPTION"[VARCHAR2,80], "T"."POSTDT"[DATE,7], "T"."TRXNSAMT"[NUMBER,22], "A"."ACCOUNTNUM"[VARCHAR2,19]
    1121
    9/10/2013 3:30
    NESTED LOOPS
    3
    2
    3
    1
    (#keys=0) "AL"."FROMACCOUNTID"[NUMBER,22], "T"."TRXNSID"[NUMBER,22], "T"."TRXNSTYPEID"[NUMBER,22], "T"."DESCRIPTION"[VARCHAR2,80], "T"."POSTDT"[DATE,7], "T"."TRXNSAMT"[NUMBER,22], "A"."ACCOUNTNUM"[VARCHAR2,19]
    1121
    9/10/2013 3:30
    NESTED LOOPS
    4
    3
    4
    1
    5
    1
    119
    3989858
    4
    (#keys=0) "AL"."FROMACCOUNTID"[NUMBER,22], "T"."TRXNSID"[NUMBER,22], "T"."TRXNSTYPEID"[NUMBER,22], "T"."DESCRIPTION"[VARCHAR2,80], "T"."POSTDT"[DATE,7], "T"."TRXNSAMT"[NUMBER,22], "A".ROWID[ROWID,10]
    1
    1121
    9/10/2013 3:30
    NESTED LOOPS
    5
    4
    5
    1
    4
    1
    90
    3989690
    3
    (#keys=0) "AL"."FROMACCOUNTID"[NUMBER,22], "T"."TRXNSID"[NUMBER,22], "T"."TRXNSTYPEID"[NUMBER,22], "T"."DESCRIPTION"[VARCHAR2,80], "T"."POSTDT"[DATE,7], "T"."TRXNSAMT"[NUMBER,22]
    1
    1121
    9/10/2013 3:30
    HASH JOIN
    SEMI
    6
    5
    6
    1
    3
    2
    54
    3989094
    2
    AL."TOACCOUNTID"="TOACCOUNTID"
    (#keys=1) "AL"."FROMACCOUNTID"[NUMBER,22]
    1
    1121
    9/10/2013 3:30
    INDEX
    FULL SCAN
    SP
    ACCOUNTLINK_AK1
    AL@SEL$1
    INDEX (UNIQUE)
    ANALYZED
    7
    6
    7
    1
    1
    18
    252
    107
    1
    AL."FROMACCOUNTID"[NUMBER,22], "AL"."TOACCOUNTID"[NUMBER,22]
    1
    SEL$5DA710D3
    1121
    9/10/2013 3:30
    VIEW
    SYS
    VW_NSO_1
    VW_NSO_1@SEL$5DA710D3
    11
    VIEW
    8
    6
    7
    2
    2
    18
    234
    107
    1
    TOACCOUNTID[NUMBER,22]
    1
    SEL$683B0107
    1121
    9/10/2013 3:30
    CONNECT BY
    NO FILTERING WITH START-WITH
    9
    8
    8
    1
    TOACCOUNTID=PRIOR "FROMACCOUNTID"
    TOACCOUNTID=56354162
    TOACCOUNTID[NUMBER,22], "FROMACCOUNTID"[NUMBER,22], PRIOR NULL[22], LEVEL[4]
    SEL$683B0107
    1121
    9/10/2013 3:30
    INDEX
    FULL SCAN
    SP
    ACCOUNTLINK_AK1
    ACCOUNTLINK@SEL$3
    INDEX (UNIQUE)
    ANALYZED
    10
    9
    9
    1
    1
    18
    252
    107
    1
    ACCOUNTLINK.ROWID[ROWID,10], "FROMACCOUNTID"[NUMBER,22], "TOACCOUNTID"[NUMBER,22]
    1
    SEL$3
    1121
    9/10/2013 3:30
    TABLE ACCESS
    BY INDEX ROWID
    SP
    TRXNS
    T@SEL$1
    2
    TABLE
    ANALYZED
    11
    5
    6
    2
    1
    1
    63
    298
    1
    T."TRXNSID"[NUMBER,22], "T"."TRXNSTYPEID"[NUMBER,22], "T"."DESCRIPTION"[VARCHAR2,80], "T"."POSTDT"[DATE,7], "T"."TRXNSAMT"[NUMBER,22]
    1
    SEL$5DA710D3
    1121
    9/10/2013 3:30
    INDEX
    RANGE SCAN
    SP
    TRXNS_ACCOUNTID_NIDX
    T@SEL$1
    INDEX
    ANALYZED
    2
    12
    11
    7
    1
    1
    1
    224
    1
    AL."FROMACCOUNTID"="T"."ACCOUNTID" AND "T"."POSTDT">=SYSDATE@!-2 AND "T"."POSTDT"<=SYSDATE@!
    T.ROWID[ROWID,10], "T"."POSTDT"[DATE,7]
    1
    SEL$5DA710D3
    1121
    9/10/2013 3:30
    INDEX
    UNIQUE SCAN
    SP
    ACCOUNT_PK
    A@SEL$1
    INDEX (UNIQUE)
    ANALYZED
    1
    13
    4
    5
    2
    1
    1
    90
    1
    A."ACCOUNTID"="AL"."FROMACCOUNTID"
    A.ROWID[ROWID,10]
    1
    SEL$5DA710D3
    1121
    9/10/2013 3:30
    TABLE ACCESS
    BY INDEX ROWID
    SP
    ACCOUNT
    A@SEL$1
    3
    TABLE
    ANALYZED
    14
    3
    4
    2
    1
    1
    29
    168
    1
    A."CLOSEDATE"<SYSDATE@! AND "T"."POSTDT">"A"."CLOSEDATE"
    A."ACCOUNTNUM"[VARCHAR2,19]
    1
    SEL$5DA710D3
    1121
    9/10/2013 3:30
    INDEX
    RANGE SCAN
    SP
    TRXNSTRACK_TRXNSID_NIDX
    TRCK@SEL$6
    INDEX
    ANALYZED
    2
    15
    1
    2
    2
    1
    1
    10
    73
    1
    TRCK."TRXNSID"=:B1 AND "TRXNSTRACKREASONID"=1
    TRCK."TRXNSID"[NUMBER,22], "TRXNSTRACKREASONID"[NUMBER,22]
    1
    SEL$6
    Please help me in debugging this thanks!

    Hi,
    Thanks for your thought on this subject. Below is the trace info that I got from the DBA
    SQL ID: d0x879qx2zgtz Plan Hash: 4036333519
    SELECT /*+ INDEX(T TRXNS_ACCOUNTID_NIDX) */ AL.FROMACCOUNTID OLDACCOUNTID ,
      A.ACCOUNTNUM OLDACCOUNTNUM, T.TRXNSID, T.TRXNSTYPEID, T.DESCRIPTION ,
      T.POSTDT, T.TRXNSAMT
    FROM
    ACCOUNTLINK AL, TRXNS T, ACCOUNT A WHERE AL.TOACCOUNTID IN (SELECT
      TOACCOUNTID FROM ACCOUNTLINK START WITH TOACCOUNTID = :B3 CONNECT BY PRIOR
      FROMACCOUNTID = TOACCOUNTID) AND AL.FROMACCOUNTID = T.ACCOUNTID AND
      A.ACCOUNTID = AL.FROMACCOUNTID AND NOT EXISTS (SELECT 1 FROM TRXNSTRACK
      TRCK WHERE TRCK.TRXNSID = T.TRXNSID AND TRXNSTRACKREASONID = :B4 ) AND
      T.POSTDT > A.CLOSEDATE AND T.POSTDT >= :B2 AND T.POSTDT <= :B1
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        0      0.00       0.00          0          0          0           0
    Execute  17160      2.10       1.87          0          0          0           0
    Fetch    17160   7354.61    7390.86     169408    5569856  883366791           0
    total    34320   7356.71    7392.74     169408    5569856  883366791           0
    Misses in library cache during parse: 0
    Optimizer mode: CHOOSE
    Parsing user id: 38     (recursive depth: 1)
    SQL ID: gs89hpavb4cts Plan Hash: 3415795327
    SELECT A.ACCOUNTID, C.MEMBERID, A.PROGRAMID, A.ACCOUNTNUM
    FROM
    CUSTOMER C, CUSTOMERACCOUNT CA, ACCOUNT A, PROGRAMPARAMVALUE PPV,
      BATCHPROCESSPROGRAM BP WHERE A.PROGRAMID = BP.PROGRAMID AND A.PROGRAMID =
      PPV.PROGRAMID AND A.ACCOUNTID = CA.ACCOUNTID AND CA.PERSONID = C.PERSONID
      AND PPV.PARAMID = :B2 AND PPV.VALUE = 'Y' AND BP.PROCESSID = :B1 AND BP.RUN
      = 'Y' AND A.ACCOUNTTYPEID = 4 AND A.ACCOUNTSTATUSID = 1 AND C.MEMBERID IS
      NOT NULL
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        0      0.00       0.00          0          0          0           0
    Execute      0      0.00       0.00          0          0          0           0
    Fetch      172     13.14     115.34      80826     278650          0       17200
    total      172     13.14     115.34      80826     278650          0       17200
    Misses in library cache during parse: 0
    Parsing user id: 38     (recursive depth: 1)
    OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        0      0.00       0.00          0          0          0           0
    Execute      0      0.00       0.00          0          0          0           0
    Fetch        0      0.00       0.00          0          0          0           0
    total        0      0.00       0.00          0          0          0           0
    Misses in library cache during parse: 0
    OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        0      0.00       0.00          0          0          0           0
    Execute  17160      2.10       1.87          0          0          0           0
    Fetch    17332   7367.75    7506.21     250234    5848506  883366791       17200
    total    34492   7369.85    7508.09     250234    5848506  883366791       17200
    Misses in library cache during parse: 0
        2  user  SQL statements in session.
        0  internal SQL statements in session.
        2  SQL statements in session.
    Trace file: svoprod_ora_12346.trc
    Trace file compatibility: 11.1.0.7
    Sort options: default
           1  session in tracefile.
           2  user  SQL statements in trace file.
           0  internal SQL statements in trace file.
           2  SQL statements in trace file.
           2  unique SQL statements in trace file.
       66499  lines in trace file.
        7516  elapsed seconds in trace file.

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

Maybe you are looking for

  • Unhandled exception while opening excel file from e-business suite form

    Hello, I am getting error ORA-106561 (Unhandled errorg) when I am trying to open excel sheet which is reside in my desk top from Oracle E-business suite customized form using dde.app_begin('C:\Program Files\Microsoft Office\Office12\EXCEL.EXE'||'d:\e

  • Audigy 4 speaker advice ple

    I have just brought a Audigy 4 card and while I am satisfied with it'sperformance I have an issue with my current speakers. I have at the moment the creative DTT2500 cambridge soundworks. Theseare great quailty speakers but they only have 2 analog in

  • I cannot copy files from Macbook to Iomega hard drive

    I wanted to use my Iomega hard drive on my macbook for the first time but I cannot copy any files. Can anybody provide me with the steps I have to do to configure the Iomega (formerly used on a PC) for the Macbook? Thanks

  • Full screen quicktime at 1680 x 1050

    Have any of you heard that quicktime running full screen at 1680 x 1050 can be a problem because the 1050 height is not divisible by four???

  • Function Key mapping

    Hi, I have migarted the form from 6i to 10g. But when i am doing *"Ctrl+L"* to see the LOV is not working, i have checked *"fmrweb.res"* for function key mapping it written *76 : 2 : "Ctrl+L" : 29 : "List of Values"* and i have changed "Ctrl+L" to "C