Tuesday, 20 August 2013

Why can Oracle not select truthiness of a statement in the order by cluase

Why can Oracle not select truthiness of a statement in the order by cluase

If I want to order a table by one column, but extract one specified row to
the top, in MySQL, I can do something like this... (fiddle)
select * from name
order by surname != 'moon', surname
However, when I want to do this in oracle, the truthy test in the order by
clause does not work, and I end up having to do something like this...
(fiddle)
select surname from name
order by case when surname = 'moon' then 0 else 1 end, surname
What is the reason for Oracle not supporting truthy tests in the order by
clause?
(or even the select statement for that matter)



Results
(all are in alphabetical order, except moon which has floated to top)
SURNAME
moon
adane
bell
day
larkin
williams

No comments:

Post a Comment