Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: How to get "...WHERE test IN (5,23,2,12,56)" in this order
Thomas,
this one is genius!
Thank you very much!
Greetings, Dirk
....
> SQL> select *
> 2 from t
> 3 order by instr( ',' || '5,23,2,12,56' || ',', ',' || x || ',' );
>
> X
> ----------
> 5
> 23
> 2
> 12
> 56
>
>
> See, the second query is orderd by the list you supply. Now, if the that
list
> can contain whitespace and such, you'll want to use REPLACE() on it to
remove
> the whitespace so the numbers are all:
>
> ,NUMBER,NUMBER,NUMBER,
....
> >> Thomas Kyte (tkyte@us.oracle.com) http://asktom.oracle.com/
> >> Expert one on one Oracle, programming techniques and solutions for
Oracle.
> >> http://www.amazon.com/exec/obidos/ASIN/1861004826/
> >> Opinions are mine and do not necessarily reflect those of Oracle Corp
> >>
Received on Fri Jan 18 2002 - 06:39:17 CST