在 Oracle 中,当我的内部查询包含 SDO_ANYINTERACT 时,为什么我不能在外部查询中选择 rownum?

发布于 2024-08-17 23:28:14 字数 1453 浏览 14 评论 0原文

我在 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..

I have written 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

The inner query is selecting rows from MY_TABLE using a bounding box. The outer queries are included to enable paging for the results.

For some odd reason this query does not yield any results. If I try and run the 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 yields 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 is preventing the query from yielding any results. If I remove rownum the results are 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..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ゃ懵逼小萝莉 2024-08-24 23:28:14
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

请参阅这篇文章。

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

See this article.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文