Sorting a resultset

Hi,
How can I sort a resultset based on a particular column value?
thanks in advance

Actually, as I retrieve more then 5000 rows, I do not want my prgram to hit the db each time when request is received. That's the first reason. the second reason is that, I'm showing the result on a page-by-page basis also want to sort a particular page's result. I mean to sort the resultset for a particular set of records. (say from 30th to 45th records)

Similar Messages

  • Re: [iPlanet-JATO] Sorting a resultset

    Steve,
    Todd will probably address this more, but to set the stage for the discussion,
    I will chime in. As per your scenario "say a user wants to resort the results
    by some other column" , I think there needs to be some clarification on the
    life cycle of the model. You scenario implies that the user sees the data and
    then submits a request to sort the data. This implies that the access to the
    same data is spread across two HTTP requests.
    Unless explicitly or implicitly stored in session, the Model is a per request
    object. Therefore, under ordinary circumstances a new instance of Model is
    constructed per request and populated as needed. This is done for scalability
    reasons. Most applications would not scale properly if all model instances were
    kept around in session per user. There is also the issue of data integrity, a
    model stored in session may not reflect the current state of the RDBMS from
    which the data was previously retrieved, perhaps minutes before. So, the
    default action is to instantiate a new model and repopulate that model The
    normal solution would be to apply the sort criteria to the data retrieval at
    that point.
    What I described above is the norm and the default.
    If you have compelling reasons to prefer a single retrieval style, you have to
    be prepared to store the Model data in session. There are several methods
    within the ModelManager class which assist in this regard. You can see them
    described in the java doc.
    Also bear in mind that the SQLModelBase typically copies the data from the JDBC
    result set into JATO specific local storage. This is done because the JDBC
    result set is not as flexible as developer needs and requires the JDBC
    connection to remain open while it is used.
    I suspect that Todd will describe how you can manipulate the underlying JATO
    specific local storage to change the order. I just wanted to make sure you
    understood the life cycle issues involved and had justification for deviating
    from the default.
    Also, I'm still waiting for followup on the defaultCommandChild issue - we'd
    like to fix it for JATO 1.2.1 if it is a problem and so far your case is the
    only one we have heard of.
    ----- Original Message -----
    From: stephen_winer
    Sent: Wednesday, December 12, 2001 9:42 AM
    Subject: [iPlanet-JATO] Sorting a resultset
    If I want to sort a result set (Model) after the search has taken
    place (say a user wants to resort the results by some other column),
    can this be done without issuing another query? The reason I ask is
    that the next() method in the ResultSetModelBase calls synchronizeRow
    (), which resets the row, which sounds like a sort done outside of
    the SQL would be reverted.
    Steve
    For more information about JATO, please visit:
    http://developer.iplanet.com/tech/appserver/framework/index.jsp
    [Non-text portions of this message have been removed]

    The hidden field was present in the page, but it looked like this:
    <input type="hidden" name="jato.defaultCommand" value=""../search"">
    Seems like there is a small bug in the code generating this tag.
    FYI - I am using JATO1.2
    What file displays this text? Maybe I can go in and fix it and rejar
    it.
    Steve
    --- Mike Frisino wrote:
    Steve,
    Can you check the HTML source that shows up in the browser? Do you see an entry that looks like this at the bottom of the form in
    question?
    >
    <input type="hidden" name="jato.defaultCommand" value="/search">
    To answer your question - it should work as you described. Some of the JatoSample make use of the defaultCommandChild. Can you try
    running the sample BasicSample->Field Types and let us know what you
    see.
    >
    Failing this you can send me your jsp file , maybe there is some subtle issue there. michael.frisino@s...
    >
    >
    ----- Original Message -----
    From: stephen_winer
    Sent: Friday, December 07, 2001 8:05 AM
    Subject: [iPlanet-JATO] Using the defaultCommandChild in a form
    I am trying to set the defaultCommandChild in my jato:form tag to be
    the searcg button. The search button definition is:
    <jato:button name="search"/>.
    The form tag definition is:
    <jato:form name="PendingIA" defaultCommandChild="/search">
    Clicking on the search button works fine, but hitting return in one
    of the textFields (which submits the form) passes a value of "" to
    the createChild method in my viewBean, which throws an error. Why
    does this not just work as normal and trigger the handleSearchRequest
    () method?
    Steve
    For more information about JATO, please visit:
    http://developer.iplanet.com/tech/appserver/framework/index.jsp
    Service.
    >
    >
    >
    [Non-text portions of this message have been removed]

  • Sorting in Resultset view of MDM Webdynpro component

    Hi
    is sorting functionality can be configured in Result set table columns by using MDM web dynpro configuration manger?
    Thanks in advance.
    Ravindra Singh

    found out the solution

  • Sort results on app or database side?

    I'd like to think that this is a bit trickier than it might first appear. We have some queries that use ORDER BY, and our database guy is telling us to take them out and do them on the web app side to cut down on Oracle 10g's use of the TEMP table. Here's an example of a frequently run query that populates a quick access select box of their address book entries:
    SELECT ReceiverID FROM ADDRESSBOOK WHERE AccountNbr = ? ORDER BY UPPER(ReceiverID)We realized that ORDER BY is probably redundant there since the pair key consists of the AccountNbr and ReceiverID, so since it'll use the index they'll come across already sorted. However, when you go searching, you have queries like this, and even more complicated ones as well:
    SELECT ReceiverID, CompanyName FROM ADDRESSBOOK WHERE AccountNbr = ? AND UPPER(CompanyName) LIKE UPPER(?) ORDER BY UPPER(CompanyName)In that case, we need to sort, either in the database or on the application side. Typically, the results per account number are around 200 or less, but sometimes it's in the thousands. I've always thought you're supposed to make the database do stuff like this, but if the database is having to go out to disk to use the TEMP table, then maybe in this case it could be better to sort the ResultSet in Java...I was happy to find out that String already has a Comparator for that, so you can write:
    Collections.sort(myList, String.CASE_INSENSITIVE_ORDER)However, on the main address book page, they see about five fields of each entry, and they can sort by any of the five fields. So, say the field they want to sort by is CompanyName. Then I'll have to put all the CompanyNames into a List and also into a HashMap where they're a key to the rest of the fields, and then sort the List and pull the CompanyNames out one by one to get the rest of the fields whose info needs to go on the same line on the webpage. In other words, this seems to be the reason for using ORDER BY on the database side in the first place, so please correct me if I'm wrong...

    You're not wrong. Databases are designed and optimized to do exactly what you're doing; a dba that tells you otherwise would be suspect in my opinion.

  • Using Decode in Order By clause

    Hi all,
    I've a prblem with the DECODE in ORDER BY clause
    Could you please advise if I did something wrong with my sort order.
    Actually,I've a store procedure which gather all information from several tables and return with a resultset.
    Therefore I just post an example table_resultset instead of lenghthy StoreProc in forum
    /* table contain the column need to be sort on the resultset */
    create table table_sort (sortnum,sortname) as
    select 1553, 'IDNO' from dual union all
    select 1231, 'IDNAME' from dual union all
    select 1001, 'CREDATE' from dual;
    /* a sample of some information that resultset return by a storeproc */
    create table table_resultset (idno,idname,credate) as
    select 1111, 'SORT ORDER', sysdate-7 from dual union all
    select 54555, 'NEED A TEST CASE', sysdate+5 from dual union all
    select 10012, 'BEYOND THE LIMIT', sysdate from dual union all
    select 10522, 'CONCENTRATION', sysdate+20 from dual union all
    select 01231, 'A VALIDATION', sysdate-3 from dual;
    /* this select statement similar to execute a storeproc with s decode in the ORDER BY clause */
    select * from table_resultset
    order by decode((select ltrim(rtrim(sortname)) from table_sort where sortnum=1231),'IDNO',1,'IDNAME',2,3);
    OR
    select * from table_resultset
    order by case (select ltrim(rtrim(sortname)) from table_sort where sortnum=1231)
    when 'IDNO' then 1
    when 'IDNAME' then 2
    else 3
    end;
    Thanks.

    Thanks for the tip Samb ... :)
    I got it ... all sort field must be same datatype.
    SQL> create table table_sort (sortnum,sortname) as
    2 select 1553, 'IDNO' from dual union all
    3 select 1231, 'IDNAME' from dual union all
    4 select 1001, 'CREDATE' from dual;
    Table created.
    SQL> create table table_resultset (idno,idname,credate) as
    2 select 1111, 'SORT ORDER', sysdate-7 from dual union all
    3 select 54555, 'NEED A TEST CASE', sysdate+5 from dual union all
    4 select 10012, 'BEYOND THE LIMIT', sysdate from dual union all
    5 select 10522, 'CONCENTRATION', sysdate+20 from dual union all
    6 select 01231, 'A VALIDATION', sysdate-3 from dual;
    Table created.
    SQL> select * from table_resultset;
    IDNO IDNAME CREDATE
    1111 SORT ORDER 08-07-03
    54555 NEED A TEST CASE 08-07-15
    10012 BEYOND THE LIMIT 08-07-10
    10522 CONCENTRATION 08-07-30
    1231 A VALIDATION 08-07-07
    SQL> select * from table_sort;
    SORTNUM SORTNAM
    1553 IDNO
    1231 IDNAME
    1001 CREDATE
    if I want to sort the resultset by the column IDNAME of table_resultset then
    SQL> select * from table_resultset
    2 order by decode((select ltrim(rtrim(sortname)) from table_sort
    3 where sortnum=1231),'IDNO',to_char(idno),'IDNAME',idname,to_char(credate,'yyyymmdd'));
    IDNO IDNAME CREDATE
    1231 A VALIDATION 08-07-07
    10012 BEYOND THE LIMIT 08-07-10
    10522 CONCENTRATION 08-07-30
    54555 NEED A TEST CASE 08-07-15
    1111 SORT ORDER 08-07-03
    if I want to sort the resultset by the column CREDATE of table_resultset then
    SQL> select * from table_resultset
    2 order by decode((select ltrim(rtrim(sortname)) from table_sort
    3 where sortnum=1001),'IDNO',to_char(idno),'IDNAME',idname,to_char(credate,'yyyymmdd'));
    IDNO IDNAME CREDATE
    1111 SORT ORDER 08-07-03
    1231 A VALIDATION 08-07-07
    10012 BEYOND THE LIMIT 08-07-10
    54555 NEED A TEST CASE 08-07-15
    10522 CONCENTRATION 08-07-30
    But if I want to sort the resultset by the column IDNO of table_resultset then I've a problem due to the field converted into character, and the field IDNO define as number(9) of a table in production. therefore I've to find a solution when that field convert into character must be same length in order to sort IDNO correctly. As you can see from below
    SQL> select * from table_resultset
    2 order by decode((select ltrim(rtrim(sortname)) from table_sort
    3 where sortnum=1553),'IDNO',to_char(idno),'IDNAME',idname,to_char(credate,'yyyymmdd'));
    IDNO IDNAME CREDATE
    10012 BEYOND THE LIMIT 08-07-10
    10522 CONCENTRATION 08-07-30
    1111 SORT ORDER 08-07-03
    1231 A VALIDATION 08-07-07
    54555 NEED A TEST CASE 08-07-15
    your suggestion always welcome.
    Thanks,
    DT.

  • Fetching all the resource request

    Hi,
    How to retrieve all the resource requests using a method?
    The below method returns the requests for a spefic resource object with the status as "Approved".
    tcResultSet rs= reqIntf.getRequestsForObject("iPlanet User", "approved");
    I want to retrieve all the resource requests.
    Thanks & Regards
    Inbaa

    public Thor.API.tcResultSet findRequests(java.util.Map phAttributeList)
    throws Thor.API.Exceptions.tcAPIException,
    tcAPIException
    Returns a list of requests that match the provided attribute list.
    Just give your criteria from the list (you can see this API in the given link)
    I haven't tried but give:
    Map a = new Hashmap();
    a.put("Objects.Object Status.Status","*");
    Then you can sort this resultset depends on your use case.
    It should work..
    http://otndnld.oracle.co.jp/document/products/id_mgmt/idm_903/doc_cd/javadocs/operations/Thor/API/Operations/tcRequestOperationsIntf.html#findRequests(java.util.Map)
    Let me know the results...
    AND
    getRequestsForObject will give you all the request for one object only.
    Edited by: Dost

  • Aggregation Function

    I followed an example on the web and created a LIST() aggregation function to transpose rows to a comma delimited string. After certain length, the result appears to be out of order. I thought it was parallel_enable issue, but it's the same after I removed the clause from CREATE FUNCTION statement.
    For example, the following SQL
    SELECT LIST(column_name) FROM user_tab_columns
    WHERE table_name='TEST' ORDER BY column_id
    generate the following string:
    c122,c123,c124,...,c1,c2,c3,...,c121
    What should I do to correct this behavior? Thanks.
    Here is the script:
    create or replace type ListType as object
    (list varchar2(4000),
    static function ODCIAggregateInitialize(sctx IN OUT ListType) return number,
    member function ODCIAggregateIterate(self IN OUT ListType, value IN varchar2) return number,
    member function ODCIAggregateTerminate(self IN ListType, returnValue OUT varchar2, flags IN number) return number,
    member function ODCIAggregateMerge(self IN OUT ListType, ctx2 IN ListType) return number
    create or replace type body ListType
    is
    static function ODCIAggregateInitialize(sctx IN OUT ListType)
    return number is
    begin
    sctx := ListType(null);
    return ODCIConst.Success;
    end;
    member function ODCIAggregateIterate(self IN OUT ListType, value IN varchar2)
    return number is
    begin
    self.list := self.list || ',' || value;
    return ODCIConst.Success;
    end;
    member function ODCIAggregateTerminate(self IN ListType, returnValue OUT varchar2, flags IN number)
    return number is
    begin
    returnValue := rtrim(ltrim(self.list,','),',');
    return ODCIConst.Success;
    end;
    member function ODCIAggregateMerge(self IN OUT ListType, ctx2 IN ListType)
    return number is
    begin
    self.list := self.list|| ',' || ctx2.list;
    return ODCIConst.Success;
    end;
    end;
    create or replace function list(input varchar2) return varchar2
    parallel_enable aggregate using ListType;
    grant EXECUTE on list to PUBLIC
    /

    in 10g, you could use something like
    regexp_replace( list(distinct to_char(column_id,'0000')||':'||column_name), '([:[digit]:]){4}:')
    if you need to support 9i, you cannot use regular expression, but you can write your own function and concatenated substr. kind of loop with instr(:) and substr()
    HTH
    Laurent
    Message was edited by:
    Laurent Schneider
    but, if you need to sort, use ORDER BY. my solution is a not recommended, it is a very dirty trick
    Message was edited by:
    Laurent Schneider
    use order by within your aggregate function, to sort the resultset each time, as advised by tom kyte in the link above

  • Order by on a non-base table field

    I want to order by on a non-base table field in a form. Can any body help how to do this in a form.
    Thanks

    Ramesh,
    I am not sure of ver 4.5. But in v6i, I did something similar.
    What I did was :-
    1. Based the Block's datasource on a stored procedure and
    not TABLE
    I'm not sure if it can be achieved in 4.5. First check if the block data source can be based on a stored procedure.
    Here's a sample code of what i did :-
    /* Description : Using a stored procedure as a block datasource.
    Author : Shailender Mehta
    Create Or Replace PACKAGE my_datasource Is
    /* Shailender Mehta */
    TYPE outrec is RECORD (comp_id tbgp_gl_detail.comp_id%Type
    ,cc_id tbgp_gl_detail.cc_id%Type
    ,journal_no tbgp_gl_detail.journal_no%Type
    ,account_code tbgp_gl_detail.account_code%Type
    ,debit_amt tbgp_gl_detail.debit_amt%Type
    ,credit_amt tbgp_gl_detail.credit_amt%Type
    ,sort_order Number(1)
    TYPE outcur is REF CURSOR RETURN outrec;
    PROCEDURE outquery (resultset In Out outcur
    ,p_journalno In Number);
    END;
    Create Or Replace PACKAGE BODY my_datasource IS
    PROCEDURE outquery(resultset In Out outcur
    ,p_journalno In Number)
    Is
    BEGIN
    OPEN resultset FOR
    SELECT comp_id
    , cc_id
    , journal_no
    , account_code
    , debit_amt
    , credit_amt
    , Decode(substr(account_code,6,1), 'g', 1,
    'd', 2,
    'b', 3,
    'h', 4,
    'f', 5,
    'a', 6,
    'c', 7, 8) sort_order
    FROM tbgp_gl_detail
    WHERE journal_no = p_journalno
    ORDER BY 7;
    END;
    END;
    Use the Block Data Wizard, which will guide you step by step what next to be done.
    In my example, I'm sorting the resultset by the 6th character of the string Account Code.
    In your case, you could join the main table by the one used in your POST-Query in the stored procedure and sort the resultset.
    - Shailender -

  • Database Record Filtering

    Hey,
    I was if there is a way to filter my repeat region by fields.
    Is there a way in which i can have the field titles (top of the records) act as a filtering system?
    E.g. If i click on Author, my recordset will filter by author ascending?
    Below is an image of my current inventory setup.
    Also, is there a way which I can add a search bar which will only show records which have the same information as what was searched for?
    Any help would be very much appreciated!
    Thank you!

    >How would I go about being able to sort the records just by clicking the headings,
    Dreamweaver does not provide a facility for this. There are two basic methods
    1) Submit the item clicked back to the query which modifies the Order By clause which sorts the resultset.
    2) Use DOM table sorting techniques. I like this better as it is more responsive
    sorttable: Make all your tables sortable
    >how would I add a search bar which will only show the records with what was searched for?
    You could use DW's search and result page behaviors
    Dreamweaver Help | Building search and results pages
    But the sooner you move away from obsolete server behaviors and onto modern coding techniques the better.

  • Sorting the elements of the ResultSet

    Hi all,
    I have a problem here. I get all the data from the database and store it in the ResultSet. I then display the same data from the result set in the front end. Is there any way such that i can sort the contents of the result set. Such that i can display the sorted emenets in the front end.
    Please give me a solution. I am stuck with this problem.
    Regards
    Pranamya

    Hello,
    Thanks for replying. My problem is
    g. My problem is that i have the data got in the
    result set. I have to arrange this data in my UI such
    that it should be arranged first in ascending order
    and then in descending order on mouse click . And if
    i use the order by clause of the SQL then this will
    result in a lots of Database operation, Which should
    be avoided.
    sigh The result set is a pointer to a row in a view. You can't sort a pointer.
    Make the UI sort the view it provides of your model. You should not modifiy the model itself for that.

  • How to apply sort on an already dispaled resultset from a procedure

    Hi,
    I have a data block for which the 'query data source type' is PROCEDURE. When I query the block all the records in the procedure are displayed. Then I query for a specific value for the DATE column (ex: 27/07/2010) and it displays records for only 27/07/2010. Now I want to sort the displayed records.
    My columns are DATE, TRANSACTION NUMBER, PROJECT CODE
    I have a button each for DATE, TRANSACTION NUMBER, PROJECT CODE to do the sorting. When I click on the PROJECT CODE sort button , the already retireved records for 27/07/2010 must be sorted according to project code.
    But this is not happening. The current coding will query the data block for all the records and then apply the sorting for DATE column.
    Please advise.

    Actually i don't know but what i gave u but i have read that If you attempt setting the where clause in the block it is totally ignored.
    i hardly search just found the following...
    Subject:  How to Filter Rows on Block Based on Stored Procedure in Oracle Forms? 
      Doc ID:  Note:1078147.6 Type:  PROBLEM 
      Last Revision Date:  22-JUN-2004 Status:  PUBLISHED 
    Problem Description: 
    ==================== 
    Whilst in ENTER QUERY mode you would like to specify a search criteria to 
    restrict the results of your query.  The block on which this query resides
    is based on a stored procedure. 
    Problem Explanation: 
    ==================== 
    If you attempt setting the where clause in the block it is totally ignored. 
    This happens with both the 'Ref Cursor' or 'Table of Records' variable.    
    Problem References: 
    =================== 
    [Search Words: filter ]
    Solution Summary: 
    =================
    With Forms 5.0 and above, you can use the Tools--> Datablock Wizard menu 
    in the Object Navigator to enter the datablock wizard in a re-enterant mode.
    You can then specify the query criteria there. 
    Alternatively, you can pass the query criteria from Forms to the stored 
    procedure as an IN argument. You can then use the parameter with the 
    select statement (in the procedure you have created using the 'Table of Records
    or 'Ref Cursor').
    Solution Description: 
    ===================== 
    If the blocks were created using the Datablock Wizard with the
    "stored procedure" radio button, you can always re-enter the datablock wizard
    for that block by clicking on the Tools-->Datablock Wizard. If you go to the 
    Query tab on the bottom of the tab page you will notice that it requests the 
    name of the parameter. This is where you enter -
       :parameter.<parameter_name> 
    This method relies on having a parameter in the form that passes the 
    value, for example p_deptno, into the stored procedure. This is done in order
    to get the corresponding records from the emp table for all employees who work
    in that deptartment.
    Additionally create a PRE-QUERY trigger and assign the value of the deptno you 
    are passing through this parameter using the following:
       (:parameter.<parameter_name>:= :dept.deptno).
    If the blocks were created manually, however, YOU CANNOT use the re-enterant 
    option to go to the Datablock Wizard. For these type of blocks, use the method
    suggested below.
    METHOD FOR MANUALLY CREATED BLOCKS:
    ===================================
    Re-enter the Datablock Wizard by using the Tools--> Datablock Wizard menu of the 
    Object Navigator.  You will notice that you will not be able to see any 
    procedure in the Datablock Wizard in re-enterant mode.
    To use this method, you will need to include one more parameter to your query
    procedure as an IN parameter. For example, if you are passing deptno as query
    criteria, click on the "Query Data Source Arguments" of your block property 
    sheet and include the following:
        ARGUMENT NAME: set to  P_DEPTNO or (any variable name)
        TYPE: set to the appropriate datatype, for example, NUMBER
        TYPENAME: set to dept.deptno%type, for example
        MODE: set to IN
        VALUE: set to :dept.deptno(the :blockname.itemname you are passing
                                   as query criteria.).
    In the query procedure, include this parameter as an IN argument, and as the 
    2nd parameter.  For example:
        Procedure  empquery_refcur(emp_data IN OUT empcur, v_dno IN number) AS ....
    Finally, include this paramter in your select statement of either 'Table of 
    Records' or 'Ref Cursor' as
        select empno, ename
         from emp
          where deptno=nvl(v_dno, deptno);But no chance to Sort it may be from inside the procedure itself.
    Hope this helps...
    Regards,
    Abdetu...

  • ResultSet merge

    Does anyone know if there is a way of creating one result set from two?
    I need to write a query to return results from two databases that can not talk to each other (!). The results are only seen after some java fantasticness has turned them into an excel spreadsheet using POI. I'm using a class I wrote that takes the ResultSet data and turns this into an excel spreadsheet. As I already have this class, I'd rather use it than write something new.
    Basically however I look at it I get two ResultSet objects. I have three options - either find a way to merge the ResultSets (which I like the sound of, but can find no easy method to do this), use one of the ResultSets to write the sheet (leaving gaps) and fill in the gaps with the data from the other ResultSet, or write lots of new stuff that does this in another way.
    Incidentally, whilst looking through the API (java 1.3, so depressing to be so backwards!) I cannot find an implementing class of the ResultSet interface. Obviously one must exist... but where is it and what is it called (as while I'm happy to consider extending this as an option, implementing all the methods of the interface sounds like a time-consuming struggle and a tremendous bore to boot!)??

    The dbs are of two different types (Sybase and Oracle) and are both huge.
    Also the db team is based mainly in Pune, India, so while they are very good at what they do, we are seperated by their general belief that they understand what I'm saying. As we're miles from them (London) I can't tell them what I want them to do with any degree of confidence in their accuracy at following my instructions. Basically I'm preempting human errors, and also have no idea how you would start connecting the two different dbs (If I cared about that sort of thing, I'd be a DBA).
    I don't know hwat your experience of dealing with dedicated DBA's is, but mine is that if I have to rewrite this part of the program (so far a month and a half has been spent on this part), it will still be quicker than getting any major change done to an existing and robust db, let alone two. The amount of other systems that would have to be altered (albiet in a minor way) would be significant too. Of course, not being a DBa I'm probably missing a very quick easy way of effecting this change without these problems, but I generally find it easier to stick to what I know.

  • How to append a ResultSet to another ResultSet?

    Hi,
    How could I append a ResultSet to another ResultSet object if their columns are exactly the same?
    For example, I have some methods that return ResultSet objects for particular queries.
    int a = 3;
    ResultSet rs1 = getRoute(20, a);
    ResultSet rs2 = getRoute(a, 40);
    ResultSet rs3 = rs1 + rs2;
    How do I combine the two ResultSet objects together instead of writing the last statement? Thank you.
    -Henry Chang

    As I noted earlier, UNION is always going to re-sort your results and remove any duplicate rows; UNION ALL might or might not depending on the database implementation.
    I think Oracle happens to be among the databases that will produce a concatenated result FROM UNIUN ALL, without resorting, but if not, and if your database happens to be Oracle, then this will work:
    SELECT * FROM
      (SELECT test_table.*, 1 subresult_no, rownum row_no
      FROM test_table
      WHERE column_a = 20 AND column_b = 10
      ORDER BY order_no)
    UNION ALL
      (SELECT *, 2 subresult_no, rownum row_no
      FROM test_table
      WHERE column_a = 10 AND column_b = 30
      ORDER BY order_no DESC)
    ORDER BY subresult_no, rownum row_no"rownum" is an Oracle feature, it's a pseudo-column that gives the row index at that point in the computation.
    The above SQL will of course add 2 columns to your result set; you can of course suppress them by explicitly listing your selected columns; doing so is widely considered to be good practice anyway.

  • Sorting of Date field in the SQL Query useing ORDER BY

    Hi
    I am facing a problem when I am getting the results of a query from the ORacle 8i database using jdbc connection.
    The query is having a date field and I have to sort the query results using ORDER By for the Date field. The query is giving exact results in the SQL PLus interface.
    When I am getting this results in the GUI where servlets are being used an Exception is coming as not supported RefreshRow method.
    If anyone has faced this problem and have got the solutions please let me know.
    thanks
    sulfy

    That doesn't sound at all like an SQL problem.
    More like you trying to do updates on the resultset which is not allowed ...
    send a some code (not to much pls :) and we'll be
    able to help more
    cu
    Spieler

  • How to do sorting/filtering on custom java data source implementation

    Hi,
    I have an entity driven view object whose data should be retrieved and populated using custom java data source implementation. I've done the same as said in document. I understand that Query mode should be the default one (i.e. database tables) and createRowFromResultSet will be called as many times as it needs based on the no. of data retrieved from service, provided we should write the logic for hasNextForCollection(). Implementation sample code is given below.
    protected void executeQueryForCollection(Object qc, Object[] params, int noUserParams) {      
    Iterator datumItr = retrieveDataFromService(qc, params);
    setUserDataForCollection(qc, datumItr);
    hasNextForCollection(qc);
    super.executeQueryForCollection(qc, params, noUserParams);
    protected boolean hasNextForCollection(Object qc) {
    Iterator datumItr = (Iterator) getUserDataForCollection(qc);
    if (datumItr != null && datumItr.hasNext()){
    return true;
    setCallService(false);
    setFetchCompleteForCollection(qc, true);
    return false;
    protected ViewRowImpl createRowFromResultSet(Object qc, ResultSet resultSet) {
    Iterator datumItr = (Iterator) getUserDataForCollection(qc);
    Object datumObj = datumItr.next();
    ViewRowImpl r = createNewRowForCollection(qc);
    return r;
    Everything is working fine include table sorting/filtering. Then i noticed that everytime when user perform sorting/filtering, executeQueryForCollection is called, which in turn calls my service. It is a performance issue. I want to avoid. So i did some modification in the implementation in such a way that, service call will happen only if the callService flag is set to true, followed by executeQuery(). Code is given below.
    private boolean callService = false;
    public void setCallService(boolean callService){
    this.callService = callService;
    public boolean isCallService(){
    return callService;
    protected void executeQueryForCollection(Object qc, Object[] params, int noUserParams){
    if (callService)
    Iterator datumItr = retrieveDataFromService(qc, params);
    setUserDataForCollection(qc, datumItr);
    hasNextForCollection(qc);
    super.executeQueryForCollection(qc, params, noUserParams);
    Issue i have:
    When user attempts to use table sort/filter, since i skipped the service call and set null as userDataCollection, createRowFromResultSet is not called and data which i retrieved and populated to view object is totally got vanished!!. I've already retrived data and created row from result set. Why it should get vanished? Don't know why.
    Tried solution:
    I came to know that query mode should be set to Scan_Entity_Cache for filtering and Scan_View_Rows for sorting. I din't disturb the implementation (i.e. skipping service call) but overrided the executeQuery and did like the following code.
    @Override
    public void executeQuery(){
    setQueryMode(callService ? ViewObject.QUERY_MODE_SCAN_DATABASE_TABLES : ViewObject.QUERY_MODE_SCAN_ENTITY_ROWS);
    super.executeQuery();
    By doing this, i could able to do table filtering but when i try to use table sorting or programmatic sorting, sorting is not at all applied.
    I changed the code like beolw*
    @Override
    public void executeQuery(){
    setQueryMode(callService ? ViewObject.QUERY_MODE_SCAN_DATABASE_TABLES : ViewObject.QUERY_MODE_SCAN_VIEW_ROWS);
    super.executeQuery();
    Now sorting is working fine but filtering is not working in an expected way because Scan_View_rows will do further filtering of view rows.
    Question:
    I don't know how to achieve both filtering and sorting as well as skipping of service call too.
    Can anyone help on this?? Thanks in advance.
    Raguraman

    Hi,
    I have an entity driven view object whose data should be retrieved and populated using custom java data source implementation. I've done the same as said in document. I understand that Query mode should be the default one (i.e. database tables) and createRowFromResultSet will be called as many times as it needs based on the no. of data retrieved from service, provided we should write the logic for hasNextForCollection(). Implementation sample code is given below.
    protected void executeQueryForCollection(Object qc, Object[] params, int noUserParams) {
      Iterator datumItr = retrieveDataFromService(qc, params);
      setUserDataForCollection(qc, datumItr);
      hasNextForCollection(qc);
      super.executeQueryForCollection(qc, params, noUserParams);
    protected boolean hasNextForCollection(Object qc) {
      Iterator datumItr = (Iterator) getUserDataForCollection(qc);
      if (datumItr != null && datumItr.hasNext()){
        return true;
      setFetchCompleteForCollection(qc, true);
      return false;
    protected ViewRowImpl createRowFromResultSet(Object qc, ResultSet resultSet) {
      Iterator datumItr = (Iterator) getUserDataForCollection(qc);
      Object datumObj = datumItr.next();
      ViewRowImpl r = createNewRowForCollection(qc);
      return r;
    }Everything is working fine include table sorting/filtering. Then i noticed that everytime when user perform sorting/filtering, executeQueryForCollection is called, which in turn calls my service. It is a performance issue. I want to avoid. So i did some modification in the implementation in such a way that, service call will happen only if the callService flag is set to true, followed by executeQuery(). Code is given below.
    private boolean callService = false;
    public void setCallService(boolean callService){
      this.callService = callService;
    public boolean isCallService(){
      return callService;
    protected void executeQueryForCollection(Object qc, Object[] params, int noUserParams){
      if (callService) {
        Iterator datumItr = retrieveDataFromService(qc, params);
        setUserDataForCollection(qc, datumItr);
      hasNextForCollection(qc);
      super.executeQueryForCollection(qc, params, noUserParams);
    }Issue i have:
    When user attempts to use table sort/filter, since i skipped the service call and storing of userDataCollection, createRowFromResultSet is not called and data which i retrieved and populated to view object is totally got vanished!!. I've already retrived data and created row from result set. Why it should get vanished? Don't know why.
    Tried solution:
    I came to know that query mode should be set to Scan_Entity_Cache for filtering and Scan_View_Rows for sorting. I din't disturb the implementation (i.e. skipping service call) but overrided the executeQuery and did like the following code.
    @Override
    public void executeQuery(){
      setQueryMode(callService ? ViewObject.QUERY_MODE_SCAN_DATABASE_TABLES : ViewObject.QUERY_MODE_SCAN_ENTITY_ROWS);
      super.executeQuery();
    }By doing this, i could able to do table filtering but when i try to use table sorting or programmatic sorting, sorting is not at all getting applied.
    I changed the code like below one (i.e. changed to ViewObject.QUERY_MODE_SCAN_VIEW_ROWS instead of ViewObject.QUERY_MODE_SCAN_ENTITY_ROWS)
    @Override
    public void executeQuery(){
      setQueryMode(callService ? ViewObject.QUERY_MODE_SCAN_DATABASE_TABLES : ViewObject.QUERY_MODE_SCAN_VIEW_ROWS);
      super.executeQuery();
    }Now sorting is working fine but filtering is not working in an expected way because Scan_View_rows will do further filtering of view rows.
    If i OR'ed the Query Mode as given below, i am getting duplicate rows. (vewObject.QUERY_MODE_SCAN_ENTITY_ROWS | ViewObject.QUERY_MODE_SCAN_VIEW_ROWS) Question:
    I don't know how to achieve both filtering and sorting as well as skipping of service call too.
    Can anyone help on this?? Thanks in advance.
    Raguraman
    Edited by: Raguraman on Apr 12, 2011 6:53 AM

Maybe you are looking for

  • Unable to change the name of events in iPoto 08

    Hi. I have iPhoto 08, and at first it was fine. But when I transferred my photos from my nikon d40 to my iPod, and then to my iMac from the iPod, i weren´t able too change the name of the events anymore. This is very anoying. Hope someone can help me

  • Report execution time should displayed in Local Time

    Hi, I have a query related to the Report execution time. Our SAP Servers are available in US.  The Servers are configured in US Time. We have developed a Z report and used SY-UZEIT to display the Report Run Time. we also have a plant in India. When w

  • VdBench "thread=" parameter in SNIA hband workload

    Hi, Could anyone help me understand how VdBench interprets configuration file parameters within hband RunDefinition (from SNIA specifications for Energy Efficient Storages)? More precisely, I can't understand how VdBench creates IO threads for slaves

  • Really need application help

    OK, so I need to create an application that calculates and displays a monthly mortgage payment, and also displays the loan balance, principle applied, and interest applied for each payment over the course of the loan. The loan amount will be determin

  • Some help needed for installation of rich client component runtime demo

    i have dwnld the demo and also read the Instructions And while installing it asks jre/java path and my jdk is intalled in this path C:/Program Files/Java/jdk1.6.0_27/bin/ And i have typed the same path with java.exe at the last but it its says Insert