sql sort problem ?

T

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



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

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
 
L

Lew

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

Tom Anderson

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
 
J

Jim Janney

tomo said:
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.
 
J

jaap

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top