| Oracle FAQ | Your Portal to the Oracle Knowledge Grid | |
Home -> Community -> Usenet -> c.d.o.server -> Re: Altering the ORDER BY clause based on a parameter
How about this?
SELECT date_col, name_col, desc_col, num_col
FROM mytab
ORDER BY
DECODE(p_order_desc, 'ASC'
,DECODE(p_order_by,1,date_col,2,name_col,3,desc_col,
4,num_col)
) ASC
, DECODE(p_order_desc, 'DESC'
,DECODE(p_order_by,1,date_col,2,name_col,3,desc_col,
4,num_col)
) DESC
![]() |
![]() |