Details
-
New Feature
-
Status: Open (View Workflow)
-
Major
-
Resolution: Unresolved
-
None
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
- is part of
-
MDEV-35973 Oracle Compatibility Project 1 for 2025
-
- In Progress
-
- relates to
-
MDEV-10152 Add support for TYPE .. IS REF CURSOR
-
- Open
-
-
MDEV-20034 Add support for the pre-defined weak SYS_REFCURSOR
-
- Closed
-
- links to
Activity
Field | Original Value | New Value |
---|---|---|
Link | This issue is part of MDEV-35973 [ MDEV-35973 ] |
Description |
Syntax:
{code:sql} CURSOR <left paren> subquery <right paren> {code} 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: {code:sql} 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(1..' || i || ')=' || t); END LOOP; END; / CALL p1; {code} {noformat} sum(1..1)=1 sum(1..2)=3 sum(1..3)=6 {noformat} TODO: Add details (rules, restrictions, when the cursor gets closed, etc) |
Syntax:
{code:sql} CURSOR <left paren> subquery <right paren> {code} 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: {code:sql} 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; {code} {noformat} sum(t1.a<=1)=1 sum(t1.a<=2)=3 sum(t1.a<=3)=6 {noformat} TODO: Add details (rules, restrictions, when the cursor gets closed, etc) |
Remote Link | This issue links to "Cursor expressions in Oracle docs (Web Link)" [ 37330 ] |
Link |
This issue relates to |
Link | This issue relates to MDEV-10152 [ MDEV-10152 ] |
Labels | Compatibility Oracle |
Parent | MDEV-35973 [ 132608 ] | |
Issue Type | New Feature [ 2 ] | Technical task [ 7 ] |
Link | This issue is part of MDEV-35973 [ MDEV-35973 ] |
Link | This issue is part of MDEV-35973 [ MDEV-35973 ] |
Parent | MDEV-35973 [ 132608 ] | |
Issue Type | Technical task [ 7 ] | New Feature [ 2 ] |
Priority | Major [ 3 ] | Minor [ 4 ] |
Priority | Minor [ 4 ] | Major [ 3 ] |