我在Oracle中编写了一个如下所示的查询:
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
内部查询是使用边界框从MY_TABLE中选择行。包含外部查询以启用对结果的分页。
由于某些奇怪的原因,此查询不会产生任何结果。如果我尝试运行子查询:
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
按预期产生结果列表。如果我运行子查询:
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
结果集为空。以某种方式rownum阻止查询产生任何结果。如果我删除rownum,结果将返回到最里面的查询中:
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
我在这做错了什么? 我正在运行Oracle 10g ..
答案 0 :(得分:1)
with
my_query as
(
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
)
select *
from
(
select /*+ FIRST_ROWS(n) */ my_query.*, rownum rnum
from my_query
where rownum <= :last_row_to_fetch
)
where
rnum >= :first_row_to_fetch
请参阅this文章。