How can we pass dynamic column names with dynamic ASC or DESC in a select statement as in the following case:
SELECT emp_name, emp_id
FROM employee
ORDER BY (CASE WHEN :p_asc='asc' THEN :p_column_name END) ASC,
(CASE WHEN :p_asc='asc' THEN :p_column_name END) DESC;
This query is not working - column names are not accepted - please help to achieve this.
Well, it depends on tool you use. SQL*Plus lets you do that. Here's example:
Right; rows are sorted by
ENAMEcolumn inDESCending order.