Strange Behaviour of Connect By Prior query

Has anybody faced a problem like your query returns alternative record like suppose you have 10 records in a table and your connect by prior query gives you 1st, 3rd, 5th and so on. My query was working fine few days back but suddenly its giving me different result. I don't know whether there was some settings changed by someone or not.

Can't guess anything from here. You need to post the query, sample data and the result.

Similar Messages

  • Connect by prior query

    Issue with the below query. The query is not getting filtered for the condition hier_typ_c in('BS') with the connect by prior
    query. query is fetching all the hier_type_c in the table like 'BS', 'CO', 'EC' etc....
    Just wondering how do i restrict the query just to fetch the type_c ='BS' alone? why is it giving all the records??
    Select 
            Level                 as  LEVEL_CODE,
            h.HIER_PRNT_NODE_I    as  PARENT,
            h.HIER_CHLD_NODE_I    as  CHILD,
            h.HIER_CHLD_NODE_X || ' (' || h.HIER_CHLD_NODE_I || ')'   as  ALIAS
            From        (Select  Distinct HIER_CHLD_NODE_I, HIER_PRNT_NODE_I,
                                HIER_CHLD_NODE_X from .HIER_DIMN
                         where hier_typ_c in('BS') and CURR_VER_C = 'Y') h
                         Start with  h.HIER_PRNT_NODE_I = 'ROOT'
            Connect by prior
                   h.HIER_CHLD_NODE_I = h.HIER_PRNT_NODE_I
    Order by    LEVEL_CODE, parent, child

    Hi
    It loks like you're doing it right.
    By basing the CONNECT BY query on a sub-query that has this WHERE clasue:
    where hier_typ_c in('BS') and CURR_VER_C = 'Y') hyou should exclude not only nodes whose hier_typ_c is not 'BS', but also their descendants.
    Post some sample data (CREATE TABLE and INSERT statements) and the results you want from that data.
    Are you sure the query you posted is what you're actually running?
    I would expect the sub-query FROM clause to cause an error because of the '.'.
    from .HIER_DIMNEdited by: Frank Kulash on Sep 29, 2009 11:16 AM

  • Complex connect by prior query

    I need SQL(for hierarchical tree) for a function which accepts node as input parameter and returns ref cursor.
    Following is a sample tree:
    1
    --2.1
    ----3.1
    ------4.1
    --------5.1
    ----------6.1
    ----------6.2
    ----3.2
    ------4.2
    --------5.2
    --2.2
    ----3.2
    ------4.2
    --------5.2
    ----3.3
    ----3.4
    ------4.1
    --------5.1
    ----------6.1
    ----------6.2
    1 is at the root level and 2.1 & 2.2 are immediate children and so on.
    The output tree should be all related parents and children of the passed node.
    e.g:
    If the input is 4.1, the output tree will be:
    1
    --2.1
    ----3.1
    ------4.1
    --------5.1
    ----------6.1
    ----------6.2
    --2.2
    ----3.4
    ------4.1
    --------5.1
    ----------6.1
    ----------6.2
    If the input is 4.2, the output tree will be:
    1
    --2.1
    ----3.2
    ------4.2
    --------5.2
    --2.2
    ----3.2
    ------4.2
    --------5.2
    The complex part, I guess, is to remove unwanted(not related) branches from the tree.
    Following is the representation of the table RELATIONSHIP
    ID     PARENT     CHILD
    1-------1-------2.1
    2-------1-------2.2
    3-------2.1-----3.1
    4-------2.1-----3.2
    5-------2.2-----3.2
    6-------2.2-----3.3
    7-------2.2-----3.4
    8-------3.1-----4.1
    9-------3.2-----4.2
    10------3.4-----4.1
    11------4.1-----5.1
    12------4.2-----5.2
    13------5.1-----6.1
    14------5.1-----6.2
    Pls. help me out to form this CONNECT BY PRIOR query.
    Thanks in advance.

    make sure you include 2 things in your queries.
    # the row number
    # the level
    for traversing up the tree set
    level = 0 - level and
    row_number = 0 - row_number.
    you than can then do an order by row_number if you union the two queries
    for example:
    ============
    select tbl.child,
    tbl.parent,
    level lvl,
    rownum rn
    from some_table tbl
    start with tbl.parent = 4.1
    connect by prior tbl.child = tbl.parent
    union
    select tbl.child,
    tbl.parent,
    0 - level lvl,
    0 - rownum rn
    from some_table tbl
    start with tbl.child = 4.1
    connect by prior tbl.parent = tbl.child
    order by rn asc

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

  • I want to help  connect by prior query

    table structure
    node_id parent_node_id
    =======================
    100
    101 100
    102 100
    1021 102
    1022 102
    10221 1022
    10222 1022
    above example tree like-
    100
    101
    102
    1021
         1022
         10221
         10222
    i want to output like(if input 1022)
    id id1
    1022 100
    1022 102
    1022 1022
    1022 10221
    1022 10222
    create table node_temp(node_id number,parent_node_id number)
    insert into node_temp(node_id) values(100);
    insert into node_temp(node_id,parent_node_id) values(101,100);
    insert into node_temp(node_id,parent_node_id) values(102,100);
    insert into node_temp(node_id,parent_node_id) values(1021,102);
    insert into node_temp(node_id,parent_node_id) values(1022,102);
    insert into node_temp(node_id,parent_node_id) values(10221,1022);
    insert into node_temp(node_id,parent_node_id) values(10222,1022);
    Edited by: 855516 on Feb 1, 2013 1:46 PM

    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;

  • How to use simple SQL instead of Connect By Prior

    Currently, I am using "connect by prior" query in the application, but for reason I don�t want to use this connect by query so can any one please tell how does I get the same result by using SQL, I tried this by using procedure but unable to get the same result, specially LEVEL of the tree.
    So please tell, how would I get the correct data.
    Thanks in advance,
    AMIT.

    Hi,
    Whenever you have a question, it helps to post:
    (1) The version of Oracle (and any other relevant software) you're using
    (2) A little sample data (just enough to show what the problem is) from all the relevant tables
    (3) The results you want from that data
    (4) Your best attempt so far (formatted) I don't believe the unformated code you posted is what you're really running, since it has a syntax error ("... WHERE START WITH ..."). Please post code that really works with the sample data you posrted.
    (5) The full error message (if any), including line number
    Executable SQL statements (like "CREATE TABLE AS ..." or "INSERT ..." statements) are best for (2).
    If you can present your problem using commonly available tables (for example, scott.emp, which contains a hierarchy), then you can omit (2).
    Formatted tabular output is okay for (3). Type these 6 characters
    {code}
    (small letters only, inside curly brackets) before and after the tabular text, to preserve spacing.
    As Alex said, why don't you want to use CONNECT BY?
    Are you getting the correct results now, but just looking for a different way of getting them?
    Depending on your exact requirements, you could write a PLSQL function that mimics LEVEL. Don't expect it to be fast.
    Nested Sets is a completely different way of modeling trees.
    Some things are much easier with Nested Sets than they are using the Adjacency Model (the parent-child model that uses CONNECT BY).
    But some things are much harder with Nested Sets, and LEVEL is one of them.

  • 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

  • Strange behaviour of hierarchical query

    Hi,
    there is two tables T(P,PK,...) (with hierarchy) and S(ID,IDS,....) with additional data.
    I take query:
    select S.IDS from T, S
    where T.PK=S.ID
    start with P=start number
    connect by prior PK=P
    Query work fine and return rows ...
    but when I add another where condition
    select S.IDS from T, S
    where T.PK=S.ID and S.IDS=searched number
    start with P=start number
    connect by prior PK=P
    query do not return rows even when searched number is in set returned by first query without additional condition.
    It seems to me strange ... thanks for idea

    Hi,
    The subquery match's the outer query rows.
    In this event the IN condition returns FALSE. Hence the query runs with out any error.
    As IN is concern the condition will look for True Or False Only.Error will happen only if any syntax issue else the query will still run.
    you can mention any coulmn name of outer query in subquery eventhough they dont exisit , the inner query can reference the outer query's column names.
    I hope you are clear on this...........
    Raj.
    Edited by: infant_raj on May 4, 2009 7:44 AM

  • Strange behaviour in SOAP connection mode

    Hello,
    I created a custom worklist app using SOAP connetion mode and I experiencing strange behaviour using it.
    Sometimes it works and sometimes not. The only difference beetwen the two working config is nearly nothing. Just server restart are performed to make it work or not. No config files or applications deployement are done between two restart.
    So It's lotery to get it work.
    When it doesn't work, I have the following error messaging (see below)
    Does anyone have a clue to get it work each time ?
    Regards.
    ORABPEL-30509
    Error in invoking task query service.
    A client side error occured in invoking the task query service.
    Please check the exception error stack to identify the error. Contact oracle support if error is not fixable.
         at oracle.bpel.services.workflow.query.client.TaskQueryServiceSOAPClient.invoke(TaskQueryServiceSOAPClient.java:183)
         at oracle.bpel.services.workflow.query.client.TaskQueryServiceSOAPClient.authenticate(TaskQueryServiceSOAPClient.java:200)
         at oracle.bpel.services.workflow.query.client.AbstractDOMTaskQueryServiceClient.authenticate(AbstractDOMTaskQueryServiceClient.java:93)
         at eu.eca.itt.eworkflow2.controller.action.TaskListAction.process(Unknown Source)
         at eu.eca.itt.eworkflow2.controller.action.TaskListAction.execute(Unknown Source)
         at org.apache.struts.chain.commands.servlet.ExecuteAction.execute(ExecuteAction.java:58)
         at org.apache.struts.chain.commands.AbstractExecuteAction.execute(AbstractExecuteAction.java:67)
         at org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
         at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
         at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:304)
         at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
         at org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
         at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
         at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:449)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:743)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
         at com.evermind.server.http.ResourceFilterChain.doFilter(ResourceFilterChain.java:65)
         at oracle.security.jazn.oc4j.JAZNFilter$1.run(JAZNFilter.java:396)
         at java.security.AccessController.doPrivileged(Native Method)
         at javax.security.auth.Subject.doAsPrivileged(Subject.java:517)
         at oracle.security.jazn.oc4j.JAZNFilter.doFilter(JAZNFilter.java:410)
         at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:623)
         at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:370)
         at com.evermind.server.http.HttpRequestHandler.doProcessRequest(HttpRequestHandler.java:871)
         at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:453)
         at com.evermind.server.http.AJPRequestHandler.run(AJPRequestHandler.java:302)
         at com.evermind.server.http.AJPRequestHandler.run(AJPRequestHandler.java:190)
         at oracle.oc4j.network.ServerSocketReadHandler$SafeRunnable.run(ServerSocketReadHandler.java:260)
         at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:303)
         at java.lang.Thread.run(Thread.java:595)
    Caused by: javax.xml.soap.SOAPException: Unable to create SOAP connection factory: Provider com.sun.xml.messaging.saaj.client.p2p.HttpSOAPConnectionFactory not found
         at javax.xml.soap.SOAPConnectionFactory.newInstance(SOAPConnectionFactory.java:32)
         at oracle.bpel.services.workflow.query.client.TaskQueryServiceSOAPClient.invoke(TaskQueryServiceSOAPClient.java:131)
         ... 29 more

    I also tried to change connection setting with
    System.setProperty("javax.xml.soap.SOAPFactory", "com.sun.xml.messaging.saaj.soap.ver1_1.SOAPFactory1_1Impl");
    System.setProperty("javax.xml.soap.SOAPConnectionFactory", "com.sun.xml.messaging.saaj.client.p2p.HttpSOAPConnectionFactory");
    I get it work for ....... a day (or a restart I suppose) reverting back to initial settings to make it work again.
    Does It mean SOAPConnectionFactories gets corrupted upon restart once I used them ?
    Is a Service Request a good idea ?
    Regards.

  • Variable being lost after CONNECT BY...PRIOR query

    Im having an issue with the following code (snippet posted):
    SELECT ewpm_project_id INTO pro_id FROM ewpm_work_package WHERE
    ewpm_work_package_id = wp_id;
    --can return pro_id here
    SELECT ewpm_work_package_prefix, LEVEL INTO parent_prefix,
    parent_level
    FROM ewpm_work_package
    WHERE ewpm_project_id = temp_pro_id
    AND ewpm_work_package_id = wp_id
    START WITH ewpm_work_package_id = pack_id
    CONNECT BY PRIOR ewpm_work_package_id = ewpm_work_package_parent_id;
    RETURN pro_id;
    The pro_id value is correctly set during the first select statement, I
    can return the pro_id in the commented position. However, I can not
    return the value after the second select statement. All I am getting
    back is a null value. If I remove the START WITH.. CONNECT BY
    clauses in the second query, the pro_id value is returned correcly.
    Has anyone experienced this before, or know what could be causing it?

    However, I can not
    return the value after the second select statement. All I am getting
    back is a null value. If I remove the START WITH.. CONNECT BY
    clauses in the second query, the pro_id value is returned correcly.How do you use this function ? If you use it in SQL query then any
    SQL statement raising NO_DATA_FOUND exception leads to NULL returning
    as a result (like the subquery in a selection list which returns no one row):
    SQL> create function get_number
      2  return number
      3  is
      4   ret_val number;
      5  begin
      6  
      7   select 1 into ret_val from dual;
      8   return ret_val;
      9  end;
    10  /
    Function created.
    SQL> select get_number from dual;
    GET_NUMBER
             1
    SQL> create or replace function get_number
      2  return number
      3  is
      4   ret_val number;
      5   p number;
      6  begin
      7  
      8   select 1 into ret_val from dual;
      9 
    10   --This statement raises NO_DATA_FOUND
    11   select 1 into p from dual where rownum = 0;
    12 
    13   return ret_val;
    14  end;
    15  /
    Function created.
    SQL> select get_number from dual;
    GET_NUMBER
    ----------Check does
    SELECT ewpm_work_package_prefix, LEVEL
    FROM ewpm_work_package
    WHERE ewpm_project_id = temp_pro_id
    AND ewpm_work_package_id = wp_id
    START WITH ewpm_work_package_id = pack_id
    CONNECT BY PRIOR ewpm_work_package_id = ewpm_work_package_parent_id
    query return anything ?
    Rgds.

  • Query tuning for query using connect by prior

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

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

  • CONNECT BY PRIOR and performance of Query Plan

    Anyone,
    I have an SQL Statement that is performing rather slow and I am trying to figure out if I could optimize it. Here is the SQL:
       SELECT/*+ index(MAXIMO.EQNDX99) */
            maximo.equipment.eqnum, maximo.equipment.parent, LEVEL
       FROM maximo.equipment@maxi_dblink
       WHERE parent = :b1 CONNECT BY PRIOR eqnum = parent
       ORDER BY eqnum, LEVELAfter some research in this board I followed some advice found to create an index on the table for both the eqnum, parent and the parent, eqnum. EQNDX99 and EQNDX999 respectivley.
    Now the Qery Plan for this query shows the following:
    SELECT STATEMENT (REMOTE)
       SORT (ORDER BY)
          FILTER
             CONNECT BY
                 INDEX (FAST FULL SCAN) EQNDX99 (NON-UNIQUE)
                 TABLE ACESS (BY USER ROWID) EQUIPMENT
                 INDEX (RANGE SCAN) EQNDX999 (NON-UNIQUE)Now it appears to be using both indexes but it is operating through a DBLINK. Is there anything else I can do to increase performance??? It appears to be using the HINT through the link as well.
    Thanks for any help I can get,
    David Miller

    how long does it takes to complete the query?

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

  • Problem Creating a query for a hierarchical tree. [using connect by prior]

    Hi all,
    I have 2 tables.
    box (box_id, box_name)
    item(item_id, item_name, box_id)
    In a box there are several items.
    I want to create a hierachical tree to display items that are present in each box.
    LIKE:
    |---BOX1
    | |----ITEM 1
    | |----ITEM 2
    |
    |---BOX2
    | |----ITEM 1
    | |----ITEM 2
    Currently i am trying this query:
    SELECT -1 state, box_name, 'icon' icon, box_id val
    from box b, item i;
    I don't know what value to put for level, i don't know how to code the 'connect by prior' part.
    Could you please advise me?
    Michaël.
    PS. Then i will eventually use this query in forms builder.

    Note the name of this forum is "SQL Developer *(Not for general SQL/PLSQL questions)*" - so only for issues with the SQL Developer tool. Please post these questions under the dedicated SQL And PL/SQL forum.
    Regards,
    K.

  • Strange behaviour when using connection pooling with proxy authentication

    All
    I have developed an ASP.NET 1.1 Web application that uses ODP.NET 9.2.0.4 accessing Oracle Database 8i (which is to be upgraded to 10g in the coming months). I have enabled connection pooling and implemented proxy authentication.
    I am observing a strange behaviour in the live environment. If two users (User 1 and User 2) are executing SQL statements at the same time (concurrent threads in IIS), the following is occurring:
    * User 1 opens a new connection, executes a SELECT statement, and closes this connection. The audit log, which uses the USER function, shows User 1 executed this statement.
    * User 2 opens the same connection (before it is released to the connection pool?), excutes an INSERT statement, and closes this connection. The audit log shows User 1, not User 2, executed this statement.
    Is this a known issue when using connection pooling with proxy authentication? I appreciate your help.
    Regards,
    Chris

    Hi Chris,
    I tried to reproduce your complaint, but was unable to. I didnt use auditting however, just a series of "select user from dual" with proxy authentication. You might want to see if you can put together a small complete testcase for this and open a sr with support.
    Cheers
    Greg

Maybe you are looking for