做“偏移”在Oracle中,读取所有数据。

发布于 2025-01-23 01:11:53 字数 135 浏览 0 评论 0原文

我知道MySQL中的Offset 10000限制20读取了从第一到10020的所有数据,并丢弃了第一个10000数据。 Offset 10000行在Oracle中仅fetch下一个20行工作相同吗?

I know that OFFSET 10000 LIMIT 20 in Mysql reads all data from first to 10020, and discards first 10000 data.
Does OFFSET 10000 ROWS FETCH NEXT 20 ROWS ONLY in Oracle work the same?

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

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

发布评论

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

评论(1

风透绣罗衣 2025-01-30 01:11:53

不,但是当然,它必须读取排序顺序的行比例,

例如

select * from emp
order by empno

读取每一行,以便对它们进行排序,并

select * from emp
where deptno = 10
order by empno

读取10个部门的每一行,然后可以对它们进行分类。

(在一些特殊情况下,我们可以用索引等跳过,但这是一个单独的讨论)。

回到FIRST /偏移时,实际上,我们正在修改需要满足需求的查询:

select ...
from   mytable
order by col
offset 100 fetch 20

成为

select ..., row_number() over ( order by col) as r
from mytable

因为我们可以这样做

select 
from ( select ..., row_number() over ( order by col) as r
     from mytable
)
where r between 100 and 120

以符合您的获取 /偏移需求。

No, but of course it must read the proportionate of rows to satisfy the ordering sequence,

eg

select * from emp
order by empno

reads every row so they can be sorted, and

select * from emp
where deptno = 10
order by empno

reads every row for department of 10 and then can sort them.

(There's a few special cases where we can skip that with indexes etc, but that's a separate discussion).

Coming back to FETCH FIRST / OFFSET, in effect we are amending the query to satisfy that need:

select ...
from   mytable
order by col
offset 100 fetch 20

becomes

select ..., row_number() over ( order by col) as r
from mytable

because then we can do

select 
from ( select ..., row_number() over ( order by col) as r
     from mytable
)
where r between 100 and 120

to match your FETCH/OFFSET needs.

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