-
decode in order by
Hi,
I want to use decode in order by in following way -
select * from dept
order by decode(.......)
if deptno=1 then order by deptname desc, deptcity asc
if deptno=2 then order by deptno desc, deptname asc, deptcity desc
else
order by deptno desc, deptcity asc.
Can anyone please help me?
Thank you in advance.
-
I think decode() is not the tool to hammer that specific nail.
I would go with
ORDER BY
CASE
WHEN...
WHEN...
ELSE...
END
Pablo (Paul) Berzukov
Author of Understanding Database Administration available at amazon and other bookstores.
Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.
-
decode in order by
Can u please give an example ?
-
Look at the first result when you Google: Oracle, order by case statement ...
http://www.compoundtheory.com/?action=displayPost&ID=39
... isn't it a beauty?
Pablo (Paul) Berzukov
Author of Understanding Database Administration available at amazon and other bookstores.
Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|