The coding style and unnecessary nested brackets make this really hard to read and interpret. But it also does help that, contrary to some comments, an ORA-00907 doesn't always mean an uneven number of parentheses, it can indicate a more general syntax error that's caused the parser to bail out. In this case it isn't very helpful.
The problem is the order by
clause on the penultimate line, within the subquery you're comparing against with in
:
...
AND RUN.RN_RUN_ID in(Select max(RUN.RN_RUN_ID) From (((((((RELEASES JOIN RELEASE_CYCLES
...
TEST.TS_TYPE = 'LR-SCENARIO')AND TEST.TS_TEST_ID =145965
ORDER BY TESTCYCL.TC_TESTCYCL_ID)
ORDER BY TESTCYCL.TC_TESTCYCL_ID,STEP.ST_STEP_ORDER
The final ordering is obviously allowed, but in that subquery it is not. So it should end:
...
TEST.TS_TYPE = 'LR-SCENARIO')AND TEST.TS_TEST_ID =145965)
ORDER BY TESTCYCL.TC_TESTCYCL_ID,STEP.ST_STEP_ORDER
I can't test that as I don't have your schema, but a simpler demo might help demonstrate:
select d1.dummy
from dual d1
where d1.dummy in (
select dummy
from dual d2
order by d2.dummy
)
order by d1.dummy;
Error at Command Line : 6 Column : 3
Error report -
SQL Error: ORA-00907: missing right parenthesis
00907. 00000 - "missing right parenthesis"
Removing the inner order by
:
select d1.dummy
from dual d1
where d1.dummy in (
select dummy
from dual d2
)
order by d1.dummy;
DUMMY
-----
X
It is expecting to see a )
instead of that order by
, so the error does make some sense, once you know what it wrong; but it doesn't really help you narrow it down.
Incidentally, this is referenced in Oracle support document 731577.1:
Getting ORA-00907: missing right parenthesis
when using an ORDER BY
clause in a subquery. When the ORDER BY
clause is removed the query runs without error.
...
This is expected behavior per Bug 4944718
ORDER BY
in a subquery shouldn't work, since the order of the rows is passed to the outer query and has no impact.
It is allowed/ignored in an inline view, but not in a nested subquery. (Though there may be exceptions where it still doesn't throw an error...)