Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

SQL order by using decode | 11g (11.2.0.4)

rthampiApr 18 2018 — edited Apr 19 2018

Hi guys

I am trying to figure out a method to order a result returned by a query using decode with the order by clause

select empno, ename from scott.emp order by decode(:p_sort_by,'NO',empno,'NAME',ename);

The above query executes without any issues when I supply 'NO', however when 'NAME' is supplied, I get an error "Invalid number", I am curious to know what is happening. Please help me to understand the reasons behind the error. Instead of absolute column names, I tried to use 1,2. The same error was when tried to execute the query.

regards,

rajesh

This post has been answered by Frank Kulash on Apr 18 2018
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 17 2018
Added on Apr 18 2018
9 comments
1,204 views