通过pl/sql实现分页

发布于 2024-09-12 02:08:39 字数 322 浏览 4 评论 0原文

我正在尝试找出一种通过存储过程调用来实现分页的方法。例如,我有一个包含 100 行的“图像”表。一个网站将请求“第一个”12 个,然后当用户“转到下一页”时,该网站将请求下一个 12 个。

我将在参数中获取 2(p_Offset 和 p_RecordCount),我需要返回一个引用。 p_Offset 将告诉我从哪里开始获取数据,p_RecordCount 将告诉我有多少(p_Offset = 13,p_RecordCount = 12 将告诉我从第 13 行开始返回 12 行。

我们正在使用 Oracle 10g,我开始查看记录类型,但我有一种感觉,我让这变得更加困难,任何帮助将不胜感激。

I'm trying to figure out a way to implement paging via stored procedure calls. For example, I have an 'Images' table that has say 100 rows. A website is going to make a request for the 'first' 12 then when the user 'goes to the next page' the site will make a request for the next 12.

I'll be getting 2 in params (p_Offset and p_RecordCount) and I'll need to return a refcursor. The p_Offset will tell me where to start getting data from and p_RecordCount will tell me how many (p_Offset = 13, p_RecordCount = 12 will tell me to return 12 rows starting from the 13th row.

We're using Oracle 10g and I started looking at RECORD types but I have a feeling I'm making this more difficult then it needs to be. Any help would be appreciated.

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

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

发布评论

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

评论(1

忘年祭陌 2024-09-19 02:08:39

我想我已经找到了解决方案,但我仍然很好奇是否有其他/更好的方法来处理它。这是我想出的:

open refcursor for
select x.*
from (select col1, col2, row_number()
    over (order by col desc) rn
    from [table])x
where rn >= p_Offset and rownum <= p_RecordCount

I think I've got a solution but I'm still curious if there are other/better ways of handling it. Here's what I came up with:

open refcursor for
select x.*
from (select col1, col2, row_number()
    over (order by col desc) rn
    from [table])x
where rn >= p_Offset and rownum <= p_RecordCount
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文