tags:

views:

81

answers:

1

There is a functionality in Oracle which permits to use a number in parentheses instead of naming a field to order a result. Example : this query order the result by the "id" column :

select name, id
from table
order by (2)

What is the name of this functionality and where can I can read documentation on it ?

+6  A: 

Take a look here.

I don't know that it has an "official" name, but "order by position" yields a good field of hits via Google.

(You also do not need to use the parens. "ORDER BY 2,1,4" works fine).

DCookie
This is helpful. But I want to understand the "position" mechanism of Oracle. Ex. Can I use it in a GROUP BY ?
Jean-Philippe Martin
No, not in the GROUP BY clause - you must explicitly name each item exactly as it appears the select list.
DCookie
Not that it wouldn't be handy at times ;-)
DCookie