Sorting the results of CONNECT BY query

Hi,
I have a table with following columns and values:
DIS_PARENT_OID OID CREATION_TIME LEVEL
0 26750 08/02/2001 14.52.14 1
0 26751 08/02/2001 14.52.48 1
26751 26752 08/02/2001 14.53.39 2
0 26753 08/02/2001 14.53.54 1
0 26722 08/02/2001 13.58.04 1
26722 26723 08/02/2001 13.58.16 2
26723 26724 08/02/2001 13.58.29 3
26724 26725 08/02/2001 13.58.41 4
26725 26726 08/02/2001 13.58.54 5
26726 26727 08/02/2001 13.59.05 6
26727 26728 08/02/2001 13.59.15 7
26728 26729 08/02/2001 13.59.26 8
26729 26730 08/02/2001 13.59.40 9
26730 26731 08/02/2001 13.59.51 10
26731 26732 08/02/2001 14.00.05 11
26732 26733 08/02/2001 14.00.16 12
26733 26734 08/02/2001 14.00.26 13
26734 26735 08/02/2001 14.00.37 14
26735 26736 08/02/2001 14.00.48 15
26736 26737 08/02/2001 14.01.00 16
26737 26738 08/02/2001 14.01.19 17
And I used a query to fetch this tree structure like :
SELECT PRIOR PARENTID,ID,CREATION_TIME,LEVEL
FROM FORUM
START WITH PARENTID=0
CONNECT BY PRIOR OID=PARENTID;
Result:
DIS_PARENT_OID OID CREATION_TIME LEVEL
0 26722 08/02/2001 13.58.04 1
26722 26723 08/02/2001 13.58.16 2
26723 26724 08/02/2001 13.58.29 3
26724 26725 08/02/2001 13.58.41 4
26725 26726 08/02/2001 13.58.54 5
26726 26727 08/02/2001 13.59.05 6
26727 26728 08/02/2001 13.59.15 7
26728 26729 08/02/2001 13.59.26 8
26729 26730 08/02/2001 13.59.40 9
26730 26731 08/02/2001 13.59.51 10
26731 26732 08/02/2001 14.00.05 11
26732 26733 08/02/2001 14.00.16 12
26733 26734 08/02/2001 14.00.26 13
26734 26735 08/02/2001 14.00.37 14
26735 26736 08/02/2001 14.00.48 15
26736 26737 08/02/2001 14.01.00 16
26737 26738 08/02/2001 14.01.19 17
0 26750 08/02/2001 14.52.14 1
0 26751 08/02/2001 14.52.48 1
26751 26752 08/02/2001 14.53.39 2
0 26753 08/02/2001 14.53.54 1
It fetches the rows in tree structure, but i need them order by creation_time desc with group by the tree structure (the level structure need not be sorted - only the latest message should be on top ). But if I used the order by creation_time desc this qry fetches the rows in reverse tree structure.
The query should fetch the rows
ORDER BY creation_time DESC and GROUPED BY tree.
Expected Result:
DIS_PARENT_OID OID CREATION_TIME LEVEL
0 26753 08/02/2001 14.53.54 1
26751 26752 08/02/2001 14.53.39 2
0 26751 08/02/2001 14.52.48 1
0 26750 08/02/2001 14.52.14 1
0 26722 08/02/2001 13.58.04 1
26722 26723 08/02/2001 13.58.16 2
26723 26724 08/02/2001 13.58.29 3
26724 26725 08/02/2001 13.58.41 4
26725 26726 08/02/2001 13.58.54 5
26726 26727 08/02/2001 13.59.05 6
26727 26728 08/02/2001 13.59.15 7
26728 26729 08/02/2001 13.59.26 8
26729 26730 08/02/2001 13.59.40 9
26730 26731 08/02/2001 13.59.51 10
26731 26732 08/02/2001 14.00.05 11
26732 26733 08/02/2001 14.00.16 12
26733 26734 08/02/2001 14.00.26 13
26734 26735 08/02/2001 14.00.37 14
26735 26736 08/02/2001 14.00.48 15
26736 26737 08/02/2001 14.01.00 16
26737 26738 08/02/2001 14.01.19 17
please suggest a solution
thanks,
Satheesh
null

The sorting variable is always the first item in the cluster.  When you sort an array of clusters, it sorts by the first item in the cluster.  If there are two identical values in the first item, it sorts by the second item, and so on.
When you build your cluster, you want to put the items into the cluster in the sequence that you want to sort them by.  For example, if I was sorting names, I would put the last name as the first item in the cluster, then the first name, then any other information I want to keep with the name when I sort it, such as phone number, address, etc.
Bruce
Bruce Ammons
Ammons Engineering

Similar Messages

  • Sorting the results returned by a Ref cursor

    Hi All,
    I have a scenario where i am asked to sort results returned by a ref cursor.
    I have to pass the column to be sorted as the Input parameter to a stored procedure. I tried using 'order by sorting_parameter' in the ref cursor's select query, but it is not sorting the results. It is not throwing any error even.
    Please help.
    Many Thanks...

    Hi
    i came across the below reply for a thread with the similar query as above.
    <<
    Justin Cave
    Posts: 10,696
    From: Michigan, USA
    Registered: 10/11/99
    Re: sort data in ref cursor
    Posted: Feb 3, 2005 10:30 AM in response to: [email protected] Reply
    No. You could sort the data in the SQL statement from which the REF CURSOR was created, but once you have a REF CURSOR, you cannot do anything but fetch from it.
    Justin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC
    >>
    So, the results from a ref cursor cant be sorted?? There is no way out?
    Kindly advise.

  • Custom Search portlet : how to sort the result in sequence (Portal 10.1.4)

    With a Custom Search portlet how to Sort the Result By Sequence. i.e. by respecting arrangements of the items in the page of contents?
    Actually the Results Options "Order By" are : Create Date, Author, Creator, Date Updated, Display Name, Last Update by, Publish Date, Score.
    Is there an action to add the "Sequence" Order By result Option?
    Great thanks for your kind help.
    Best regards

    No, I agree that it is functionality that should be added to the product, but it
    is not a bug because it was not written to do this.
    It is a short coming of the product.
    Cheers,
    Ersan

  • I've found no way to sort.  For example, if I type the group "Rush" into the search bar, I get a list of songs recorded by rush and literally thousands of other songs and artists with the word rush in them. There is; however, no way to sort the results.

    I've found no way to sort search results in itunes.  For example, if I type the group "Rush" into the search bar, I get a list of songs recorded by rush and literally thousands of other songs and artists with the word rush in them. There is; however, no way to sort the results. 

    In the Search box click on the black Arrow and UNTICK the Search Entire Library.
    Then the Search results in Songs view will be displayed in the main Grid and you can sort them by clicking on the column headers.
    You can also turn on the column browser which can help with filtering

  • Custom Search Portlet : How to Sort the Result By Sequence (Portal 10.1.4)

    Customer request: With a Custom Search portlet how to Sort the Result By Sequence. i.e. by respecting arrangements of the items in the page of contents?
    (Like it's possible in MyOracle)
    Actually the Results Options "Order By" are : Create Date, Author, Creator, Date Updated, Display Name, Last Update by, Publish Date, Score.
    Is there an action to add the "Sequence" Order By result Option?
    Great thanks for your kind help.
    Best regards

    No, I agree that it is functionality that should be added to the product, but it
    is not a bug because it was not written to do this.
    It is a short coming of the product.
    Cheers,
    Ersan

  • End the result of an sql query by Email as an excel file attachement

    Hi,
    I would like to create a PL/SQL function that send the result of an sql query by Email as an excel file attachement.
    i'm newbie in pl/sql an d i dont know if it's possible to do such task.
    regards,

    i think a regular expression is he way to go in your case...
    Azadi Saryev
    Sabai-dee.com
    http://www.sabai-dee.com

  • Pass the result of a SQL Query as table_name  for another SQL Query

    Hi All,
    How to pass the result of a SQL Query as parameter to another SQL Query
    Eg: I am doing the steps below.
    1) select distinct table_name as TAB1 from all_tab_cols where table_name like 'T_%' and column_name like '%XYZ'
    2) I want to pass the table_name from step 1 above as parameter to another query "select * from TAB1"
    Thanks

    Naveen B wrote:
    Hi All,
    How to pass the result of a SQL Query as parameter to another SQL Query
    Eg: I am doing the steps below.
    1) select distinct table_name as TAB1 from all_tab_cols where table_name like 'T_%' and column_name like '%XYZ'
    2) I want to pass the table_name from step 1 above as parameter to another query "select * from TAB1"
    ThanksYou should craete PL/SQL code with cursor which will accept a parameter and call that cursor inside the first one
    But if the first sql returns only one row, you can do it with simple sql code
    select * from (select distinct table_name as TAB1 from all_tab_cols where table_name like 'T_%' and column_name like '%XYZ')- - - - - - - - - - - - - - - - - - - - -
    Kamran Agayev A. (10g OCP)
    http://kamranagayev.wordpress.com
    [Step by Step install Oracle on Linux and Automate the installation using Shell Script |http://kamranagayev.wordpress.com/2009/05/01/step-by-step-installing-oracle-database-10g-release-2-on-linux-centos-and-automate-the-installation-using-linux-shell-script/]

  • Ability to send the results of a report query to a table in the database

    Hi Guys
    Is it possible to send the results of a report query to a table in the database ?
    Thanks

    Yes.
    For this purpose, you can use :
    * the delivers advanced option
    http://gerardnico.com/wiki/dat/obiee/bi_scheduler/advanced_publication_delivers
    * the SOA API
    http://gerardnico.com/wiki/dat/obiee/obiee_soap_eclipse
    This two solutions need some development skills.

  • Use the results of an SQL query to create another query

    I am working on a bidding/allocation system using C# and MySQL, and I am currently having difficulty implementing the “post-allocation” mechanics of the system. Let me explain how it works, before introducing the code:
    When the bids are made on the system, they all have the position 0, so the first thing the system does is order them according to priority.
     (bid table)
    In this case, 5 bidders are interested in what is in plot 15, but we have not assigned them a position yet.
     (bid table)
    The system then organises the bids according to the order in which they are going to processed.
    The bids are then allocated, but unfortunately there are only 3 spaces in plot 15 that can be allocated. As a result, we use the priority listing to determine which bidder gets what.
     (booking table)
    At this stage, I can say that I am stuck, there are two things that I want to do, both of which involve reusing the results of the query at step 2.
     (bid table)
    The bidders that have their job allocated should see: their bid.status updated
    from Queued to Allocated,
    the bid.position should
    be set to 0,
    and their job_id should
    be set to the booking they have been allocated (i.e. booking.id).
    The bidders that have not had their jobs allocated should see: their bid.status remain
    as Queued, and their bid.position should
    be set to 0 in
    preparation for the method to run again
    The difficulty I am having is in stage 3, how do I determine which jobs have been allocated and which ones have not, and then run the necessary SQL queries in order to make the updates?
    My code so far is as follows:
    // STEP 1a - SELECT BIDS
    string query =
    "SELECT t1.operator_id, t1.datetime, t1.plot_id, t1.position, t2.market_access FROM bid t1 " +
    "JOIN operator t2 ON t1.operator_id = t2.id WHERE t1.status='Queued' AND t1.postcode=@postcode " +
    "ORDER BY t2.market_access ASC, t1.datetime ASC";
    var bidList = new List<BidList>();
    var cmd = new MySqlCommand(query, _connection);
    cmd.Parameters.AddWithValue(("@postcode"), _plot);
    MySqlDataReader dataReader = cmd.ExecuteReader();
    while (dataReader.Read())
    var item = new BidList
    OperatorId = dataReader["operator_id"] + "",
    PlotId = dataReader["plot_id"] + "",
    Position = dataReader["position"] + "",
    Datetime = dataReader["datetime"] + "",
    MarketAccess = dataReader["market_access"] + "",
    bidList.Add(item);
    dataReader.Close();
    // STEP 1b - SET PRIORITIES
    for (var i = 0; i < bidList.Count; i++)
    var position = i + 1;
    bidList[i].Position = position.ToString();
    query = "UPDATE bid SET position=@position WHERE status='Queued' AND postcode=@postcode AND operator_id=@operator_id;";
    cmd = new MySqlCommand(query, _connection);
    cmd.Parameters.AddWithValue(("@position"), position);
    cmd.Parameters.AddWithValue(("@postcode"), _plot);
    cmd.Parameters.AddWithValue(("@operator_id"), bidList[i].OperatorId);
    cmd.ExecuteNonQuery();
    dataReader.Close();
    // STEP 2 - ALLOCATE JOBS ACCORDING TO PRIORITY
    foreach (var t in bidList)
    query = "SELECT operator_id, plot_id, status FROM booking " +
    "WHERE status='open' AND postcode=@postcode AND operator_id='0'" +
    "ORDER BY datetime ASC;" +
    "UPDATE booking SET operator_id=@operator_id, status='Allocated' " +
    "WHERE (plot_id=@plot_id AND operator_id='0' AND status='Open') LIMIT 1;";
    cmd = new MySqlCommand(query, _connection);
    cmd.Parameters.AddWithValue(("@operator_id"), t.OperatorId);
    cmd.Parameters.AddWithValue(("@postcode"), _plot);
    cmd.Parameters.AddWithValue(("@plot_id"), t.PlotId);
    cmd.ExecuteNonQuery();
    dataReader.Close();
    // STEP 3
    CloseConnection();

    I can't tell.  When modifying row(s) you have to be able to uniquely be able to identify the row(s) in the database you want to modify.  That is why I recommended the other day to use DataAdapter instead of the DataReader.  You can with the
    reader, but you need to unique identify the rows.
    I can't tell from the limited amount of data you posted if in table 2 that there is only one row with the same operator id and plot id.  It looks like in table 2 the 'id' number is unique.  When working with a database with multiple tables you
    need to be able to link tables together with primary keys (columns wit unique values).  If the database isn't designed properly then it is impossible to do some operations.  So you always have to make sure you design a database properly.
    jdweng
    When you say table 2 are you referring to the bid or booking table?
    Here is the table structure for the bid table
    Here is the table structure for the booking table
    Hope it helps makes things clearer!

  • How to use the result of a sql query for a max () function

    Hi
    I wrote a query on which i wrote
    "select max(id) from users "
    how can i use the returned value.
    if i made the var name ="userid"
    can it be userid.rows[0] or what.
    thnx for any help

    Hi!
    The result of this query will be the max ID of users' IDs.
    Let say we have:
    String sql="select max(users.id) from users";
    Statement st = ctx.conn.createStatement();
    ResultSet rs = st.executeQuery(sql);
    rs.next();     
    So you can get the max Id in the following way:     
    int maxId=rs.getInt("id");
    Regards,
    Rossi

  • Presenting/Selecting the "result rows" in a query

    Hi,
    Here is a description of my problem:
    I have a query which returns values for materials grouped by purchasing groups:
    Group 1 Material A KyeFigure
    Group 1 Material B KyeFigure
    Result:  KyeFigure       
    Group 2 Material C KyeFigure
    Group 2 Material D KyeFigure
    Result: KyeFigure
    I'm using a Web application designer chart to present the values graphically. I would like only to present the result rows in the chart, not item values. But since the chart picks all KFs presented in the table (items as well) this is not the case. I've tried to find a way in the chart-settings without any luck - it seems not possible. The documentation states that you're supposed to design your table the way you want it to show in the chart. However, I'm not allowed to redesign the cube or the report. It is not possible to drill up characteristics either (this affects the calculation).
    My question is: Is there a way to extract the result rows into a new table and then base my chart on that one or simply somehow present only the result rows in a chart?
    Best Regards
    /Daniel

    Hi Daniel,
    You can create the query view in BEx Analyzer. After you execute the query, use filters, drill downs etc to get to the exact "view" of data that you would like you chart to present. Save this query view. Then in your web template assign this query view as the data provider.
    Hope this helps...

  • Returning the result of a database query to a client

    glassfish
    JAX-WS 2.0
    NetBeans 5.5
    Is it possible to send a CachedRowSet object to a client?
    I get an error when i try to do so. (I can't deploy the web service method that returns the CachedRowSet)
    Is there a better way to return the result of database query to a client?
    I'd appreciate any suggestions or sample code.

    Hi!
    The result of this query will be the max ID of users' IDs.
    Let say we have:
    String sql="select max(users.id) from users";
    Statement st = ctx.conn.createStatement();
    ResultSet rs = st.executeQuery(sql);
    rs.next();     
    So you can get the max Id in the following way:     
    int maxId=rs.getInt("id");
    Regards,
    Rossi

  • How to show only the result line of a Query result ?

    Hi Experts,
    I want to show only the result line of the Query. Is this possible in query Designer ?
    In BeX Workbook, I can hide the rows but they grow or shrink dynamically and hence it is unpredictable how many rows to suppress.
    If you have any solutions/workarounds, please reply !
    Rekha

    VBA coding can be used to display just the Result rows.
    Somthing like this - modify as needed.
    This scans the range of query results looking to find the last row, then checks those rows to see if the word Result is found or not, deleting (or you could just hide) the detail rows.  There is also a LEAF option in BEx Boolean options that returns a 1 or 0 depending on whether a row is a detail or result that could also be used to hide rows rather than looking for the presence of "Result" in a particular column
    Sub SAPBEXonRefresh(queryID As String, resultArea As Range)
    For rownum = 17 To 64000 Step 1
    ' col 2 is the Total Result, col 3 is the User Group result
    If Cells(rownum, 2) = "" And Cells(rownum, 3) = "" Then
    lastrow = rownum - 1
    Exit For
    End If
    Next
    For rownum = lastrow To 17 Step -1
    If Cells(rownum, 2) = "Result" Or Cells(rownum, 3) = "Result" Then
    Rows(rownum).Hidden = False
    Else
    ' Rows(rownum).Hidden = True
    Rows(rownum).EntireRow.Delete
    End If
    Next
    End Sub

  • Retrieving the row number of a specific record from the results of a MySQL query

    I want to create a MySQL query that will return a list of
    records, and then retrieve the row number of a record with a
    specific ID. How can I do this?
    *server-side script: PHP

    <?php
    $i = 0;
    do {
    $i++;
    } while (mysql_fetch_assoc($rsWhatever) &&
    $row_rsWhatever['ID'] !=57);
    echo "TADA -" . $i;
    ?>
    (assuming that ID is numeric, and that the test value
    actually exists in the
    database)
    Murray --- ICQ 71997575
    Adobe Community Expert
    (If you *MUST* email me, don't LAUGH when you do so!)
    ==================
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    ==================
    "AngryCloud" <[email protected]> wrote in
    message
    news:g4e6ck$hrb$[email protected]..
    >I will use this scenario for an example:
    >
    > I want to know how far down the list I will find the ID,
    '57'.
    >
    > So I manually look at the list of results and see it is
    the 25th record
    > down
    > on the list.
    >
    > How do I get my PHP script to get this number (25)
    automatically?
    >

  • Making Buttons appear depending on the results of a SQL Query

    I need some help here I am still working on a time clock program
    I need help with the clock in and out buttons i need to know how to make
    the clock in button appear only if they are not clocked in. But I can not seem
    to make the sql statement or maybe my code is wrong, it needs to just get a
    count to see if they have any entries that have 0 in the hoursworked column
    and if so then it needs to just display the clock out if not then just the clockin button needs to be displayed this was my orignal code that was not working
    <%   
        String statement = "select count(*) as cnt from TimeSheet Where idnum = " + session.getAttribute("IDNUM");
        stmt.execute(statement);
        rs = stmt.getResultSet();
        rs.next();
        int num = rs.getInt("cnt");
        if (num == 0 || num == null)
        {%>
            <tr>
                <td><input type="submit" value="Clock In" name="button"></td>
            </tr>
        <%}
        else
        {%>
            <tr>
                <td><input type="submit" value="Clock Out" name="button"></td>
            </tr>
         <% } %>but it did not work it would only display the clock out button so i need to figure this out so that the user can not clock into the program twice to get double hours and so forth.

    Does it even compile ?Yes, it wouldnt, not even in 1.5
    it needs to just get a
    count to see if they have any entries that have 0 in the hoursworked column
    and if so then it needs to just display the clock out if not then just the clockin button needs to be displayed in which case,
    1. your sql is not correct.
    2. session.getAttribute("attrName") returns an Object - is the IDNUM column of type number
    (going by the fact that you have not enclosed the value in single quotes '')
    Assuming that you have a column called 'hoursworked' in table 'timesheet' and
    IDNUM is of type NUMBER
    <%
         Integer idNum = (Integer)session.getAttribute("IDNUM");
         //from the OP ::  get a count to see if they have any entries that have 0 in the hoursworked column
         String statement = "select count(*) as CNT from TIMESHEET where IDNUM = " + idNum + " and HOURSWORKED = 0 ";
         //remaining stuff :: Look out for the error pointed out by Pgeuens
         cheers,
    ram.

Maybe you are looking for

  • Help needed in writing installers for swing application

    Hi , I want to write an installer for one of our home grown profiler tool. I need to write the installer for different platforms such as windows,linux,solaris,HP-UX. Does anybody have any idea of how to go ahead in writing installations. Share if the

  • Ethernet connectivity issue with Microsoft Small Business Server (SBS)

    Just recently updated my OS to Yosemite, and am now having ongoing problems connecting to my company's Microsoft Small Business Server (SBS). I'm having no other issues connecting to outside server's via wifi or ethernet, but once I connect to our lo

  • How to read XML payload in Adapter module

    Hi all, I have to read content of xml payload inside custom adapter module: <?xml version="1.0" encoding="UTF-8"?> <ns0:MT_REQ xmlns:ns0="namespace"> <record>   <EmployeeName>a</EmployeeName>   <EmployeeID>9999</EmployeeID>   </record> <record>   <Em

  • Petition to bring back "Print PDF" to InDesign

    Would anyone else like to join a petition for bringing back "Print PDF" as an option in the InDesign Print menu? I am on CS4 and my colleagues are on CS5 and they have no end of problems getting their PDFs the way they want them from the command near

  • Material documents archiving

    Presently trying to archive material documents through SARA and using object MM_MATBEL. Is this only for inventory maange ment or mat doc generated through process orders can also be archived (transaction type WR). For variant picking the document on