Re: Natural sort

From: Álvaro G. Vicario <alvaroNOSPAMTHANKS_at_demogracia.com>
Date: Mon, 06 Oct 2008 18:11:11 +0200
Message-ID: <gcddau$591$1@huron.algomas.org>


F Pighi escribió:
>> Does Oracle 10g have a so called "natural sort" feature? E.g.:
>>
>> foo1
>> foo2
>> foo10
>> foo100
>>
>> ... rather than:
>>
>> foo1
>> foo10
>> foo100
>> foo2

> 
> You could do something like this:
> 
> select * from YOUR_TABLE
>  order by to_number(regexp_substr(YOUR_FIELD,'^[0-9]+')),
>           to_number(regexp_substr(YOUR_FIELD,'$[0-9]+')),
>           YOUR_FIELD

I suppose the second regexp is '[0-9]+$'. Perhaps it's not a 100% generic solution but it's simple enough to be usable and it works pretty well with the actual data currently stored in the table. Thank you!

P.S. I have Oracle 10g release 10.1.0.2.0 so I can use REGEXP_SUBSTR; sorry for omitting the release.

-- 
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://bits.demogracia.com
-- Mi web de humor al baño María: http://www.demogracia.com
--
Received on Mon Oct 06 2008 - 11:11:11 CDT

Original text of this message