I wrote a query in Oracle that looks like this:
select ID, NAME, GEOMETRY from
(
select a.*, rownum as rnm from
(
select ID, NAME, GEOMETRY from MY_TABLE
where SDO_ANYINTERACT(GEOMETRY, SDO_UTIL.SDO_GEOMETRY('POLYGON ((670000 6268000, 670000 6269000, 700000 6269000, 700000 6268000, 670000 6268000))')) = 'TRUE'
order by NAME asc
) a
)
where rnm <= 50 and rnm >= 40
An internal query selects rows from MY_TABLE using a bounding box. External queries are included to enable paging for results.
For some odd reason, this query does not return any results. If I try to run a subquery:
select ID, NAME, GEOMETRY from MY_TABLE
where SDO_ANYINTERACT(GEOMETRY, SDO_UTIL.SDO_GEOMETRY('POLYGON ((670000 6268000, 670000 6269000, 700000 6269000, 700000 6268000, 670000 6268000))')) = 'TRUE'
order by NAME asc
It gives a list of results as expected. If I run the subquery:
select a.*, rownum as rnm from
(
select ID, NAME, GEOMETRY from MY_TABLE
where SDO_ANYINTERACT(GEOMETRY, SDO_UTIL.SDO_GEOMETRY('POLYGON ((670000 6268000, 670000 6269000, 700000 6269000, 700000 6268000, 670000 6268000))')) = 'TRUE'
order by NAME asc
) a
the result set is empty. Somehow rownum interferes with the query to give any results. If I remove rownum, the results will be returned as in the innermost query:
select a.* from
(
select ID, NAME, GEOMETRY from MY_TABLE
where SDO_ANYINTERACT(GEOMETRY, SDO_UTIL.SDO_GEOMETRY('POLYGON ((670000 6268000, 670000 6269000, 700000 6269000, 700000 6268000, 670000 6268000))')) = 'TRUE'
order by NAME asc
) a
What am I doing wrong here? I am running Oracle 10g ..