Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: What query can sort this?
Originally posted by Sean
> I have been trying to sort on a column of data and am stumped. Does
> anyone have any advice?
>
> The column is a VARCHAR2(15)
>
> Footnote_no
> ------------
> 1
> 1.1
> 1.2
> 1.2.1
> 1.2.2
> 1.2.2.1
> 1.4
> 1.6
> 1.10
> 1.11
> 1.12
> 1.12.1
> 1.12.1.1
>
> etc.
>
> As you can tell from the data above, it is already in a nice ascending
> order and is the ultimate result I am looking for. By just applying a
> sort you get
>
> 1.10
> 1.11
> 1.12
> 1
> etc...
>
> I think you get the idea.
>
> Any suggestions?
> Thanks,
> Sean
If you have a utility for parsing a delimited string (a useful utility), you can do something like this:
create or replace
function convcode( code in varchar2 ) return varchar2
is
v_table parse.varchar2_table; v_nfields integer; v_retval varchar2(1000);
Then:
1 select code, convcode(code) as convcode
2 from junk
3* order by convcode(code);
CODE CONVCODE -------------------- ------------------------------ 1 0001 1.1 00010001 1.2.2.1 0001000200020001 1.11 00010011 1.12 00010012 1.12.1.1 0001001200010001
-- Posted via http://dbforums.comReceived on Thu Sep 04 2003 - 08:06:12 CDT
![]() |
![]() |