最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

database - Unable to use FETCH OFFSET syntax with inner CURSOR query in Oracle SQL - Stack Overflow

programmeradmin1浏览0评论

When attempting to query a resultset with an offset and a limit with the OFFSET x ROWS FETCH y ROWS ONLY syntax outside of the inner cursor

DECLARE
  l_hits SYS_REFCURSOR;
BEGIN 
  OPEN l_hits for
    SELECT CURSOR(SELECT *
                    FROM emp) hits
      FROM dept
     ORDER BY deptno 
    OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY;
END;

results in the following error...

ERROR at line 1:
ORA-22902: CURSOR expression not allowed
ORA-06512: at line 4

Removing OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY solves it but also removes functionality.

The problem is that the goal is to offset the top level block rather than the CURSOR. How can I accomplish this?

Thank you.

When attempting to query a resultset with an offset and a limit with the OFFSET x ROWS FETCH y ROWS ONLY syntax outside of the inner cursor

DECLARE
  l_hits SYS_REFCURSOR;
BEGIN 
  OPEN l_hits for
    SELECT CURSOR(SELECT *
                    FROM emp) hits
      FROM dept
     ORDER BY deptno 
    OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY;
END;

results in the following error...

ERROR at line 1:
ORA-22902: CURSOR expression not allowed
ORA-06512: at line 4

Removing OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY solves it but also removes functionality.

The problem is that the goal is to offset the top level block rather than the CURSOR. How can I accomplish this?

Thank you.

Share Improve this question edited Feb 5 at 17:38 Joao Pereira asked Feb 5 at 17:25 Joao PereiraJoao Pereira 6036 silver badges17 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

Solved it. Ended up being pretty straightforward. Need to do the OFFSET x ROWS FETCH NEXT y ROWS ONLY in an inline view.

DECLARE
  l_hits SYS_REFCURSOR;
BEGIN 
  OPEN l_hits for
    SELECT CURSOR(SELECT *
                    FROM emp) hits
      FROM (SELECT * 
              FROM dept
             ORDER BY deptno
            OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY) dept;
END;

Hopefully it is useful for others in the future.

发布评论

评论列表(0)

  1. 暂无评论