Details

    Description

      Syntax:

      CURSOR <left paren> subquery <right paren>
      

      This example passes a cursor expression with a set of INTs to the function f1() which calculates the sum of all INTs in the set:

      DROP TABLE t1;
      CREATE TABLE t1 (a INT);
      INSERT INTO t1 VALUES (1);
      INSERT INTO t1 VALUES (2);
      INSERT INTO t1 VALUES (3);
      CREATE OR REPLACE FUNCTION f1(c SYS_REFCURSOR) RETURN INT
      AS
        v INT;
        t INT := 0;
      BEGIN
        LOOP
          FETCH c INTO v;
          EXIT WHEN c%NOTFOUND;
          t:= t + v;
        END LOOP;
        RETURN t;
      END;
      /
      CREATE OR REPLACE PROCEDURE p1
      AS
        t INT;
      BEGIN
        FOR i IN 1..3 LOOP
          SELECT f1(cursor(SELECT a FROM t1 WHERE a<=i)) INTO t FROM DUAL;
          DBMS_OUTPUT.PUT_LINE(' sum(t1.a<=' || i || ')=' || t);
        END LOOP;
      END;
      /
      CALL p1;
      

       sum(t1.a<=1)=1
       sum(t1.a<=2)=3
       sum(t1.a<=3)=6
      

      TODO:
      Add details (rules, restrictions, when the cursor gets closed, etc)

      Attachments

        Issue Links

          Activity

            There are no comments yet on this issue.

            People

              Unassigned Unassigned
              bar Alexander Barkov
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.