Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > sql sort problem ?

Reply
Thread Tools

sql sort problem ?

 
 
tomo
Guest
Posts: n/a
 
      05-25-2010
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




 
Reply With Quote
 
 
 
 
Lew
Guest
Posts: n/a
 
      05-25-2010
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
 
Reply With Quote
 
 
 
 
Tom Anderson
Guest
Posts: n/a
 
      05-25-2010
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
 
Reply With Quote
 
Jim Janney
Guest
Posts: n/a
 
      05-25-2010
"tomo" <(E-Mail Removed)> 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
 
Reply With Quote
 
jaap
Guest
Posts: n/a
 
      05-25-2010
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL Reference, SQL Queries, SQL help ecoolone ASP .Net 0 01-03-2008 10:58 AM
Re: When will Thunderbird support sort in place (in context sort)? Ron Natalie Firefox 0 02-02-2006 04:38 AM
The Colourised Bewitched -- sort of OK....... sort of! anthony DVD Video 26 06-28-2005 04:39 AM
xsl:sort lang="es" modern vs. tradidional Spanish sort order nobody XML 0 06-01-2004 06:25 AM
Ado sort error-Ado Sort -Relate, Compute By, or Sort operations cannot be done on column(s) whose key length is unknown or exceeds 10 KB. Navin ASP General 1 09-09-2003 07:16 AM



Advertisments