Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Order by Decode( )

Posted on 2004-10-04
2
Medium Priority
?
1,037 Views
Last Modified: 2010-05-18
I have a query created for a report that allows the user to select what information they wish to sort the end report by.  I uderstand that decode automatically type-casts the decode statement based on the first item decoded.  That is the problem: one of the items is a date field the rest are varchar2 fields if the date field is the first in the list then I cannot order by the other fields I get "literal does not match" or "expecting a number format..." if a varchar2 field is first in the list and the date field is selected to order by it is treated as a varchar and is not sorted properly.  Again I understand that is the way decode is supposed to work but there has to be a way around this.  I have tried to type cast from within the decode statement it does not work...at least not the way I tried.

select platform, engineer, end_date, part, complete_date, rcvd_date
from table
where....
order by (:sort, 'ENGINEER', engineer, 'EDD', end_date, 'PART', part)

the above will not correctly sort by end_date

select platform, engineer, end_date, part, complete_date, rcvd_date
from table
where....
order by (:sort,  'EDD', end_date, 'ENGINEER', engineer, 'PART', part)

the above will not correctly sort by engineer or part

any suggestions


0
Comment
Question by:Barovian
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 20

Expert Comment

by:dsacker
ID: 12219058
Try:

order by decode(:sort,'ENGINEER',engineer,'EDD',to_char(end_date,'yyyymmddhh24miss'),'PART',part)

If you don't need the hours, take off the hh24miss.
0
 
LVL 6

Accepted Solution

by:
izblank earned 2000 total points
ID: 12219151
Try this:

order by decode(:sort,  'EDD', end_date, NULL),
   decode(:sort, 'ENGINEER', engineer, NULL),
   decode(:sort, 'PART', part,NULL)
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why doesn't the Oracle optimizer use my index? Querying too much data Most Oracle developers know that an index is useful when you can use it to restrict your result set to a small number of the total rows in a table. So, the obvious side…
This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question