Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: Dynamic Order By Clause

Re: Dynamic Order By Clause

From: Dmitry E. Loginov <dmitry_loginov_at_mtu.ru>
Date: Wed, 21 Nov 2001 21:31:25 +0300
Message-ID: <9tgs3e$veo$2@gavrilo.mtu.ru>


create table T1(ID number, C1 varchar2, C2 date);

You can try something similar:
select ID,C1,C2,
  decode(:P_SORTING,

       'ID',to_char(ID,'00000000000000.0000000000000000'),
       'C1',C1,
       'C2',to_char(C2,'YYYYMMDDHH24MISS'),
       '')

from T1
order by 4

But IMHO the best way is using of dynamic (DBMS_SQL package) or native (EXECUTE IMMEDIATE) SQL for such tasks.

"Prakash C N" <prakashcn_at_hotmail.com> wrote in message news:7e1c2f8c.0111210812.416e524f_at_posting.google.com...
> Hi,
>
> Can i have a dynamic order by clause, following is my example which
> is in a package
>
> select * from tab1
> order by columnname_in
>
> columnname_in will have the actual column name
> giving the flexibility of ordering by any column which is in tab1
> with out hardcoding the column name
>
> Thanks in advance
> -Regards
> Prakash C N
Received on Wed Nov 21 2001 - 12:31:25 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US