Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: order by (asc and desc)
Eric Luu <ericluu_at_hotmail.com> wrote in article
<382202b9$0$206_at_nntp1.ba.best.com>...
: Is there a way of choosing which ordering to use
: (ascend or descend) depending on a flag.
:
: like:
:
: select a
: from abc
: order by a decode(flag, 1, asc, 2, des)
Assuming column a is a numerical one:
order by a*decode(flag, 1, 1, -1).
If a is a char one, assuming for simplicity that in contains only alphanumerical in uppercase:
def source_ = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' def destin_ = 'ZYXWVUTSRQPONMLKJIHGFEDCBA9876543210'
order by translate(a, '&&source_', decode(flag, 1, '&&source', '&&destin')).
For date column tri
order by to_char(a, 'J') *decode(flag, 1, 1, -1).
--
Alexander I.Doroshko, aid_at_grant.kharkov.ua