Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: ORDER BY question
Give them a list of fields they can order by, and retrieve the field
number,
then you can try
select last_name, first_name, emp_no from emp_table
where ...
order by decode (field_number,
1, last_name, 2, first_name, 3, to_char(emp_no,'99999'))
-- ------------ Kind reGards \ / | X | / \ x Gerard David A. Gershman <dgers_at_pizza> schreef in artikel <623hpt$42a_at_hacgate2.hac.com>...Received on Fri Oct 17 1997 - 00:00:00 CDT
> In a procedure with the select statement:
>
> select Last_name, First_Name from Emp_Table Where (Last_Name) like
'GER%'
> order by 2, 1;
>
> I'd like the ORDER BY values to be provided by an HTML form user. Hence
> the 2 and 1 would be in VarChar2 variables.
>
> Question: Is there a way to 'convert' the VarChar2 variables into a data
> type that can be used by the ORDER BY? I've tried To_Number() and it
> doesn't work, nor does putting VarChar2 variables containing the column
> names in place of 2 and 1.
>
> i.e. the following don't work...
>
> select ..... Order by Search1, Search2;
> -- Where Search1 := 'First_Name' and Search2 := 'Last_Name'
>
> nor does
>
> select ..... Order by To_Number( Search1 ), To_Number( Search2 );
> -- Where Search1 := '2' and Search2 := '1'
>
> Any and all help would be *greatly* appreciated! Thanks in advance.
>
>
> --
>
> "Artificial Intelligence: Making computers behave like they do in the
movies." > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~
> David A. Gershman : SSE Lab Administrator, MTS Comp Sci/Math
> Hughes Information Technology Systems, Fullerton California
> (714) 446-2669 - dgers_at_sed.hac.com
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~
>