Wierd sorting results

Have a java based application displaying query results from an oracle database. Sorting is done using "ORDER BY (CASE WHEN SUBSTR(field_name, 1, 1) BETWEEN '0' AND '9' THEN 0 ELSE 1 END) || NLSSORT(field_name, 'NLS_SORT = GERMAN_AI')".
Sorting is corect on development system, but on productive system order gets mixed up, i.e. first letter "c, a, b, f, d, e, i, g, h, l, j, k..."
Also, using an sql client, query returns corect order for both database layers. Seems that wrong ordering is returned only from java application on productive system.
Any ideas?

Thanks Sergiusz for great idea on tracing. Second parameter in NLS_SORT is specified so session value should not be used.
Meanwhile problem got solved by avoidance, as we have additional request to treat any consecutive digits at beginning of word as whole number (i.e. '20xxx' order before '100xxx' because 20 < 100), and we have tried ORDER BY TO_NUMBER(REGEXP_SUBSTR(field_name, '^[0-9]*')), NLSSORT(field_name, 'NLS_SORT = GERMAN_AI'). This seems to be working corectly on both layers. For sure this approach could have been used on previous requirements also.
So problem solved, maybe this workaround would help. Cannot explain it though, would be interesting if anyone can.

Similar Messages

  • Sort results in SQL Developer 3.0

    Hi,
    Looks like still auto sorting results in SQL Developer 3.0 is not supported (I see only sort history). Because of this I am still using 1.5 to look into table content.
    Would be nice to have this feature back.
    Thanks

    Hi,
    you can upgrade to SQL Developer 3.2
    Philip

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

  • Issue with sorting results on the basis of specfic values.

    Hello,
    I written an sql that will sort the results on the basis of values defined in 'IN' clause. I have made use of CASE statement in ORDER BY clause. Its not functioning. My code is:
    SELECT GWLO.productcode,
              GWLA.parentsampletype,
              GWLO.sampletype SampleType,
              max(GWLA.loginid) Loginid,
              max(GWLA.modifiedts) modifiedts
         FROM gwloginattribvars GWL,
              gwloginkeyvals GWLO,
              gwloginkeysadmin GWLA
         WHERE GWLO.productcode = GWLA.productcode
              AND GWLO.sampletype = GWLA.sampletype
              AND GWLO.productcode in ('1002124', 'ABPG', 'ABIG')
              AND GWLO.sampletype <> 'CERTIFICATE-OF-ANALYSIS'
              AND GWLA.parentsampletype IS NOT NULL
         GROUP BY GWLO.productcode, GWLA.parentsampletype, GWLO.sampletype
         ORDER BY
              (CASE GWLO.productcode WHEN '1002124'     THEN 1
                   WHEN 'ABPG'     THEN 2
                   WHEN 'ABIG'     THEN 3
                   ELSE 'LL'
                   END) ASC
    I expected the results to be in sequence what it is defined in CASE - ORDER By clause. This code is givin me error. The error is
    (CASE GWLO.productcode WHEN '1002124' THEN 1
    ERROR at line 16:
    ORA-00907: missing right parenthesis
    Please help. Thanks!

         ORDER BY
              (CASE GWLO.productcode WHEN '1002124'     THEN 1
                   WHEN 'ABPG'     THEN 2
                   WHEN 'ABIG'     THEN 3
                   ELSE 'LL'>                END) ASC
    Can u just explain me in this context? I think it should be another number in the else part - since you are returning numbers in all the 'WHEN' option. Pls explain it.
    Regards.
    Satyaki De.

  • Sort Result set in Custom Order

    Hello - Happy Friday everyone !!
    I would like result set to be sorted in a custom order, for example, a specific value must appear at top of result set, a specific value must appear at bottom of result set, and others can be sorted in standard order.
    Below is the link I found while researching for the possible solution. This works great if I have to sort a specific value to appear at top of result set but I want some specific values to appear at the very bottom as well.
    http://sqlandme.com/2013/11/18/sql-server-custom-sorting-in-order-by-clause/
    For example:
    CountryName
    AUSTRALIA
    BANGLADESH
    CHINA
    FRANCE
    INDIA
    JAPAN
    NEW ZEALAND
    PAKISTAN
    SRI LANKA
    UNITED KINGDOM
    UNITED STATES
    Now based on the popularity you might need a country to appear on top of the list. In order to return results as required, we need to specify a custom sort order in ORDER BY clause. It can be used as below.
    The following query will return result set ordered by CountryName, but INDIA at top and CHINA at 2nd "container">
    USE [SqlAndMe]
    GO
    SELECT CountryName
    FROM   dbo.Country
    ORDER BY CASE WHEN
    CountryName = 'INDIA' THEN '1'
                  WHEN
    CountryName = 'CHINA' THEN '2'
                  ELSE
    CountryName END ASC
    GO
    Result Set:
    CountryName
    INDIA
    CHINA
    AUSTRALIA
    BANGLADESH
    FRANCE
    JAPAN
    NEW ZEALAND
    PAKISTAN
    SRI LANKA
    UNITED KINGDOM
    UNITED STATES
    My predicament: Based on the example above, I always want 'India' and 'China' at the TOP and 'Bangladesh' and 'Pakistan' at the bottom. Rest can follow the general sort rule. How do I tweak/approach this? Thank you very
    much for your help in advance.
    Result Set I am anticipating;
    INDIA
    CHINA
    AUSTRALIA
    FRANCE
    JAPAN
    NEW ZEALAND
    SRI LANKA
    UNITED KINGDOM
    UNITED STATES
    BANGLADESH
    PAKISTAN
    This would make my weekend great!!
    Regards,
    SJ
    http://sqlandme.com/2013/11/18/sql-server-custom-sorting-in-order-by-clause/
    Sanjeev Jha

    this would be enough
    USE [SqlAndMe]
    GO
    SELECT CountryName
    FROM dbo.Country
    ORDER BY CASE CountryName
    WHEN 'INDIA' THEN 1
    WHEN 'CHINA' THEN 2
    WHEN 'BANGLADESH' THEN 4
    WHEN 'PAKISTAN' THEN 5
    ELSE 3
    END,CountryName
    GO
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • Wierd sorting behavior in report

    I have a report with many fields, a region to show/hide columns, and a region for searching (scalar search fields and multi-select fields). Sorting by toggling a column header doesn't sort the field, it does something, but it doesn't sort. Something really strange is I have a column named CPU Count and when I click on the column header for CPU Arch, it sorts the CPU Count column.
    I recently did the following to change NLS_SORT to BINARY_CI and
    1. In the application attributes, I set the 'Application Language Derived From'
    globalization attribute to "No NLS (Application not translated)", and
    left the 'Application Primary Language' setting alone (English...).
    2. Created a BEFORE HEADER and ON SUBMIT BEFORE COMPUTATIONS application level process as a PL/SQL Anonymous Block to force the NLS settings using ALTER SESSION commands. Set the Sequence to 0 for both.
    execute immediate 'ALTER SESSION SET NLS_DATE_FORMAT="DD-MON-YYYY"';
    execute immediate 'ALTER SESSION SET NLS_SORT="BINARY_CI"';
    Could this have had any impact? I don't know if column sorting worked before I made those changes or not. Looking for ideas before I take this out.
    Karen

    Karen,
    The good news is that we can see the problem you are having.
    The bad news is that we're going to have to ask you to do a bit more work so we can get to the bottom of it. If you don't mind, here is the request from Marc (our reports engine expert):
    "I tried to figure out what's going on with this report, but I don't know. My guess would be some combination of changed column sequence, conditional
    display of columns and show/no show columns. I tried a number of different scenarios locally, but they always worked. And in the example that user sent
    us, the first couple of columns seem to be working fine. I tried purging preferences, etc., but I'm still getting strange results for e.g. the usage
    column. I would need to get a reproducible case set up on my local PC, so that I can add some more debug output to reports3.plb. So if this person
    could provide us with a simplified example, incl. DDL script and data load scripts that we can install locally, I can a try to investigate this further. It would also help if the user could either step by step re-create this report, with perhaps fewer columns, without changing the column sequence at first, and only later hooking up column conditions, so that we can get some more information on when the sorting gets messed up."
    Thanks,
    Scott

  • Need to sort results in a report in descending order

    Hi,
    We have OIM 10g and we need to sort the report on date in descending order. I tried this code but still the column is not getting sorted.
    Evertime I generate the report, the results are sorted only in ascending order.
    Here the stored procedure code for sorting:
    strOrderByClause := 'abc.date';
    IF strsortorder_in = 'DESC' THEN
    intSortDirection_in := 0;
    ELSE
    intSortDirection_in := 1;
    END IF;
    Please let me know if you have faced similar issue.
    Thanks,
    Kalpana.

    Hi,
    If Oracle can give you back the right sort order without any custom sorting,
    that means you should be able to get the same results in WebI.
    If the object that you pull from the universe is the wrong type (like numeric but you want it alphanumeric),
    then you can either request you designer to give you an object with the right data type,
    or you can change it by creating a report variable using
    FormatNumber([original object],"0")
    this will format the number to a number without leading zeroes, thousand separators or decimal point.
    Now you can use the object as if it came from the universe.
    So you can also use it on the x-axis of a chart.
    Btw. you can also do a custom sort on the x-axis(as long as it is an object or variable, not a formula)
    alternative, if you define a custom sort in a table block, you can state it should be used througout the document.
    (so also in the charts.
    Hope this helps,
    Marianne

  • Unable to sort result list in a search crm 2007

    Hello everyone,
    I am facing a problem in CRM 2007, Iu2019m going to describe it.
    When I try to sort or filter a result list in the webclient, It is done by clicking on the header of the result list, well when i click on it instead of appearing the options ( such as ascending , descending or any value of the selection) there is a error in the web page ( so a sign of error appears in the left bottom corner of the screen)
    For instance if i search an account with a * then many possible accounts will appear in the result list, but i can not sort them by clicking on the header of the result list.
    Any help?
    Thanks in advance.
    Luis Angel Fiel

    Hi Masood,
    You understand it correctly, but in the result list We have more that one column. No header of any column is working.
    For instance when I am searching for an account in the result list will appear several accounts ( in lines ) and several columns in the columns there are  fields (STRUCT.ACT_DATE     STRUCT.CREATE_BY      STRUCT.DESCRIPTION     STRUCT.STA TXT) but no one of those headers are working.
    Thank you very much for your answer.
    Luis Angel Fiel

  • Sort results Datafinder by property name

    Hello All,
    I would like to sort my resultlist by property.name = "BENCH":
    Dim oMyDataFinder, oMyQuery, MyDate, MyMin, oMyResults
    Set oMyDataFinder = Navigator.ConnectDataFinder("My DataFinder")
    If oMyDataFinder.Name = "My DataFinder" Then
    Dim AdvancedQuery
    Set  AdvancedQuery =Navigator.CreateQuery(eAdvancedQuery)
    AdvancedQuery.ReturnType=eSearchFile
    Call AdvancedQuery.Conditions.Add(eSearchFile,"BENCH","=", "*")
    oMyDataFinder.Search(AdvancedQuery)
    Set oMyResults = oMyDataFinder.Results
    on error resume next
    Call oMyResults.Elements.Sort("BENCH",FALSE)
    msgbox(err.number&"  "&err.description)
    end if
    the error is "438 proprietà o metodo non supportati dall'oggetto"
    oMyResults.Elements.count is 1
    what is the problem?
    can i sort by date ("DatatypeDate" property type)?
    Thanks,
    Yustas
    Solved!
    Go to Solution.

    Hello Yustas,
    your variable "oMyResults" is already an elements collection so it does not have an elements member.
    Try to use this instead:
    Call oMyResults.Sort("BENCH",FALSE)
    Hope that helps,
    Eva

  • Toggle Group Visibility while sorting results in error

    I have a custom website in which we have embedded SQL Server Reporting Services reports.  
    The report in question has 3 nested row groups.  The parent group is always shown, but the 2 child groups default to hidden and have their visibility toggled by the parent group.  This works fine by itself.
    There are several columns for which we've enabled Interactive Sorting.  This also works fine by itself.  
    The problem occurs when the user sorts a column first, then toggles the visibility of the child groups.  Toggling the groups before sorting works fine for some reason.  The Error only occurs when sorting, then toggling visibility.
    The error is a reporting services error.  It says 
    The value for parameter 'SortItem' is not specified. It is either missing from the function call, or it is set to null. (rsMissingParameter) Get
    Online Help
    There is no parameter in the report called "SortItem", so this seems to be some internal error which is triggered from this specific sequence of events.
    Additionally, this error only occurs when the report is embedded in the custom website.  This error does not occur when running the report in the standard reporting server website or in Visual Studio.  
    Any ideas on how to fix this?

    Hi Jahbreeze,
    Thank you for your question.
    I am trying to involve someone more familiar with this topic for a further look at this issue. Sometime delay might be expected from the job transferring. Your patience is greatly appreciated. 
    Thank you for your understanding and support.
    Best regards,
    Qiuyun Yu
    Qiuyun Yu
    TechNet Community Support

  • Verity - How to sort results?

    How can one sort a set of data returned by CFSEARCH?
    I'm using CF7.
    Thank you!

    quote:
    Originally posted by:
    therearentanyleft
    I appreciate your comment and will certainly answer questions
    when I know a solution. Thanks for your response. Can you help me
    understand what you mean by "Try query of queries"?
    Only to a limited degree because I've never used
    <cfsearch>
    Macromedia book Developing Cold Fusion MX Applications has an
    example on page 460. The name attribute of your cfsearch tag
    becomes the table name in your cfquery tag. The example alludes to
    a field called score, but I don't know where that came from.

  • Get unique sort result ids

    ID SORT
    2000001 1
    2000054 1
    2000161 1
    2004102 1
    2000126 8
    2000161 8
    2004102 8
    2000001 51
    2000054 51
    2000161 51
    2004102 51
    2000126 58
    2000161 58
    2004102 58
    Output
    ID SORT
    2000001 1
    2000054 1
    2000161 1
    2004102 1
    2000126 8
    2000161 8
    2004102 8
    we want all unique ID values with minimum sort values

    Try the below:
    ;With cte
    as
    (Select *,Row_number() over(partition by id order by SORT asc) Rn From Table)
    Select * From cte
    Where Rn=1

  • Wierd arithmatic result....

    All,
    I have a field with datatype char and length 15. I am filling it with value like '000000006528954'. I need to have the value 65289.54, so I am dividing the field with 100. But I keep on getting something like 65290. I tried changing the dataytpe for target field from char,packed,numeric but I dont get what I want. Can somebody please let me know whats going wrong??
    Appriciate your inputs...
    Thanks in advance
    Sam

    Hi ,
    One method is to convert the data type to NUMC and perform 'value/100' then you will get the result.
    One more method is to condense the value and follow the procedure.
    len = strlen( field name) - 2.
    concatenate field0(len) ',' fieldlen(2) into anotherfield.
    Eg: Field1 Contains '000000006528954'.
    Field2(16)  type c.
    Length = strlen( field1 ) - 2.
    concatenate Field10(Length) ',' Field1Length(2) into Field2.
    <REMOVED BY MODERATOR>
    Thanks and Regards.
    Edited by: Alvaro Tejada Galindo on Apr 3, 2008 4:40 PM

  • Sort result of multple query to table model

    I have two query at the db
    query 1 return this coloumn
    NAME SURNAME COLOR
    query 2 return:
    NAME SURNAME AGE
    I MUST build a tablemodel that contain
    NAME SURNAME COLOR AGE
    order by NAME, SURNAME
    Is it possible?
    I don't know what is the best way....

    use one of these (your choice)
    http://java.sun.com/j2se/1.4.2/docs/api/java/util/Collection.html
    implement this
    http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Comparable.html
    or make one of these
    http://java.sun.com/j2se/1.4.2/docs/api/java/util/Comparator.html
    use methods here
    http://java.sun.com/j2se/1.4.2/docs/api/java/util/Collections.html
    read this
    http://java.sun.com/docs/books/tutorial/collections/index.html
    use your collection in one of these to "back" the data
    http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/table/AbstractTableModel.html

  • How to sort web app items based on few fields of it on search result page?

    I have a web app and its search. The search results are on multiple pages means it has pagination. My client's requirement is to have a feature which will sort results based on some web app items. for example we have a field price so when user select the price it needs to sort from high to low. Any one have idea how to do it?

    I have just been playing around with this for something else, all you need to do is duplicate your price field into the weighting field and it will automatically sort from High to low for you.
    Cheers
    Duncan

Maybe you are looking for