Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-10142 PL/SQL parser
  3. MDEV-12314

sql_mode=ORACLE: Implicit cursor FOR LOOP for cursors with parameters

    XMLWordPrintable

    Details

    • 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    |
      +-------+-------+
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                bar Alexander Barkov
                Reporter:
                bar Alexander Barkov
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: