sql sort problem ?

Discussion in 'Java' started by tomo, May 25, 2010.

  1. tomo

    tomo Guest

    I have three elements in list "a", "1","b". Java sort will give me 1,a,b,
    but when i do order by column_name asc in DB, oracle gives me a,b,1 . How
    can I write SQL query to get string sorted just like the way java does?
    Thanks



    __________ Information from ESET NOD32 Antivirus, version of virus signature database 5143 (20100525) __________

    The message was checked by ESET NOD32 Antivirus.

    http://www.eset.com
     
    tomo, May 25, 2010
    #1
    1. Advertising

  2. tomo

    Lew Guest

    On 05/25/2010 06:13 AM, tomo wrote:
    > I have three elements in list "a", "1","b". Java sort will give me 1,a,b,
    > but when i [sic] do order by column_name asc in DB, oracle [sic] gives me a,b,1 . How
    > can I write SQL query to get string sorted just like the way java does?


    Please provide an SSCCE
    http://sscce.org/

    What is your Java code?

    What is your SQL (both DDL and query)?

    What is the locale for both Java and the database?

    You have asked, "I have a problem. What is the solution?"

    There isn't enough detail to know, but the questions I asked are what you
    should ask yourself, and the answers are what make a solution possible.

    --
    Lew
     
    Lew, May 25, 2010
    #2
    1. Advertising

  3. tomo

    Tom Anderson Guest

    On Tue, 25 May 2010, tomo wrote:

    > I have three elements in list "a", "1","b". Java sort will give me
    > 1,a,b, but when i do order by column_name asc in DB, oracle gives me
    > a,b,1 . How can I write SQL query to get string sorted just like the way
    > java does?


    This isn't a java question, it's an Oracle question. Take it to an Oracle
    group.

    tom

    --
    Vive la chimie, en particulier, et la connaissance en general. --
    Herve This
     
    Tom Anderson, May 25, 2010
    #3
  4. tomo

    Jim Janney Guest

    "tomo" <> writes:

    > I have three elements in list "a", "1","b". Java sort will give me 1,a,b,
    > but when i do order by column_name asc in DB, oracle gives me a,b,1 . How
    > can I write SQL query to get string sorted just like the way java does?
    > Thanks


    That's the behaviour you get when the data is encoded in EBCDIC.
    Assuming that's the problem, it may be possible to write something
    like

    select * from data order by ASCII_STR(column_name)

    where ASCII_STR is a SQL function that converts the data to ASCII.
    You'd have to check the Oracle docs to see if they have anything like
    that.

    Problems are that you lose portability, if you care about that, and
    that the database can't use an index in the ORDER BY so it has to sort
    the result set in memory before sending it to you. Sorting in Java
    may be faster.

    --
    Jim Janney
     
    Jim Janney, May 25, 2010
    #4
  5. tomo

    jaap Guest

    Op 25-05-10 12:13, schreef tomo:
    > I have three elements in list "a", "1","b". Java sort will give me 1,a,b,
    > but when i do order by column_name asc in DB, oracle gives me a,b,1 . How
    > can I write SQL query to get string sorted just like the way java does?
    > Thanks
    >


    A Java List is not sorted, it keeps the order in which you insert the
    elements. A database has no defined order, that's why you use the "order
    by" clause. If the order is important, you can use an extra field with a
    number and use that field in the "order by".

    Succes,
    Jaap
     
    jaap, May 25, 2010
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. nobody
    Replies:
    0
    Views:
    539
    nobody
    Jun 1, 2004
  2. JerryJ
    Replies:
    11
    Views:
    1,407
    Dave Moore
    Apr 28, 2004
  3. John Black
    Replies:
    6
    Views:
    2,064
    John Harrison
    May 28, 2004
  4. ecoolone
    Replies:
    0
    Views:
    765
    ecoolone
    Jan 3, 2008
  5. Navin
    Replies:
    1
    Views:
    702
    Ken Schaefer
    Sep 9, 2003
Loading...

Share This Page