PL/SQL parser (MDEV-10142)

[MDEV-12314] sql_mode=ORACLE: Implicit cursor FOR LOOP for cursors with parameters Created: 2017-03-21  Updated: 2023-10-04  Resolved: 2017-03-22

Status: Closed
Project: MariaDB Server
Component/s: Parser, Stored routines
Affects Version/s: 10.3
Fix Version/s: 10.3.0

Type: Technical task Priority: Major
Reporter: Alexander Barkov Assignee: Alexander Barkov
Resolution: Fixed Votes: 0
Labels: Compatibility

Issue Links:
Blocks
is blocked by MDEV-12098 sql_mode=ORACLE: Implicit cursor FOR ... Closed
Problem/Incident
causes MDEV-32275 getting error 'Illegal parameter data... Closed
Relates
relates to MDEV-16674 Document FOR loop Open
Sprint: 10.2.2-3, 10.2.2-1, 10.2.2-2, 10.2.2-4, 10.1.18

 Description   

This is similar to MDEV-12098, but for cursors with parameters.

The below script demonstrates using of a FOR loop with a cursor cur that has two parameters.

DROP TABLE IF EXISTS t1;
DROP PROCEDURE IF EXISTS p1;
SET sql_mode=ORACLE;
CREATE TABLE t1 (a INT, b VARCHAR(32));
INSERT INTO t1 VALUES (10,'b0');
INSERT INTO t1 VALUES (11,'b1');
INSERT INTO t1 VALUES (12,'b2');
DELIMITER $$
CREATE PROCEDURE p1(pa INT, pb VARCHAR(32)) AS 
  CURSOR cur(va INT, vb VARCHAR(32)) IS
    SELECT a, b FROM t1 WHERE a=va AND b=vb;
BEGIN
  FOR rec IN cur(pa,pb)
  LOOP
    SELECT rec.a, rec.b;
  END LOOP;
END;
$$
DELIMITER ;
CALL p1(10,'B0');
CALL p1(11,'B1');
CALL p1(12,'B2');
CALL p1(12,'non-existing');
DROP TABLE t1;
DROP PROCEDURE p1;

The expected output is:

+-------+-------+
| rec.a | rec.b |
+-------+-------+
|    10 | b0    |
+-------+-------+
+-------+-------+
| rec.a | rec.b |
+-------+-------+
|    11 | b1    |
+-------+-------+
+-------+-------+
| rec.a | rec.b |
+-------+-------+
|    12 | b2    |
+-------+-------+



 Comments   
Comment by Alexander Barkov [ 2017-03-22 ]

Pushed to bb-10.2-compatibility

Generated at Thu Feb 08 07:56:45 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.