Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting the 'Order By' Clause from plsql procedure parameters

Tags:

sql

oracle

plsql

What is the best way to dynamically set the 'order by' column name and direction from parameters passed in to a plsql procedure?

like image 249
haymansfield Avatar asked Dec 10 '22 14:12

haymansfield


1 Answers

You can use variables if you order using a case:

select  *
from    YourTable
order by
        case when par_name = '1' then col1
             when par_name = '2' then col2
        end
,       case when par_name = '3' then col3
        end desc
like image 69
Andomar Avatar answered May 26 '23 22:05

Andomar