I need to order transaction based on the currency.
However I need to implement a custom order by, which makes the USD to always comes on the top, and the rest should be ordered asc.
for example :
- BHT
- USD
- MYR
- JYP
should be sorted like :
- USD
- BHT
- JPY
- MYR
Is there a simple way to handle this?
Don’t know if this qualifies as simple:
or a bit more compact but Oracle specific:
The above solution using numbers to defined the sort order will not automatically sort currencies correctly that aren’t mentioned in the case/decode expression.
To simply put USD at the front and don’t care about the rest, the “generated” order criteria must be a character value as well. You can use the following in that case:
Which uses an “alphabetical” ordering. This works because characters are sorted after the number digits. (Using
'AAA'instead of'001'would work as well).