The issue there is that you are using it in a scalar query, ie, a select as a column.
Easier if we format it:
SQL> select
2 dummy,
3 'Just a test rownum and order in SELECT part' acomment,
4 (Select dummy
5 from dual
6 where rownum= 1
7 order by dummy) ask_case
8 from dual;
order by dummy) ask_case
*
ERROR at line 7:
ORA-00907: missing right parenthesis
Its unrelated to rownum, for example:
SQL> select
2 dummy,
3 'Just a test rownum and order in SELECT part' acomment,
4 (Select dummy
5 from dual
6 order by dummy) ask_case
7 from dual;
order by dummy) ask_case
*
ERROR at line 6:
ORA-00907: missing right parenthesis
In all cases (scalar or not) the query:
select ..
from any_table
where rownum <= ...
order by ....
is almost always a bug because of the way SQL works, namely:
- apply the WHERE predicate first
- THEN apply the ORDER BY
Let's say we have "rownum <= 10". This means we just grab 10 *random* rows, and then sort them. It does NOT get the 10 highest/lowest rows.
For that you need an inline view or the FETCH FIRST syntax.