Details

    • Sprint:
      10.2.2-3, 10.2.2-1, 10.2.2-2, 10.2.2-4, 10.1.18

      Description

      Under terms of this task we'll add support for ROW type variables as SELECT..INTO targets.

      Example:

      SET sql_mode=DEFAULT;
      DROP TABLE IF EXISTS t1;
      DROP PROCEDURE IF EXISTS p1;
      CREATE TABLE t1 (a INT, b VARCHAR(32));
      INSERT INTO t1 VALUES (10,'b10');
      DELIMITER $$
      CREATE PROCEDURE p1()
      BEGIN
        DECLARE rec1 ROW(a INT, b VARCHAR(32));
        SELECT * FROM t1 INTO rec1;
        SELECT rec1.a, rec1.b;
      END;
      $$
      DELIMITER ;
      CALL p1();
      

      +--------+--------+
      | rec1.a | rec1.b |
      +--------+--------+
      |     10 | b10    |
      +--------+--------+
      

      Example for sql_mode=ORACLE:

      SET sql_mode=ORACLE;
      DROP TABLE IF EXISTS t1;
      DROP PROCEDURE IF EXISTS p1;
      CREATE TABLE t1 (a INT, b VARCHAR(32));
      INSERT INTO t1 VALUES (10,'b10');
      DELIMITER $$
      CREATE PROCEDURE p1 AS
        rec1 ROW(a INT, b VARCHAR(32));
      BEGIN
        SELECT * FROM t1 INTO rec1;
        SELECT rec1.a, rec1.b;
      END;
      $$
      DELIMITER ;
      CALL p1();
      

      +--------+--------+
      | rec1.a | rec1.b |
      +--------+--------+
      |     10 | b10    |
      +--------+--------+
      

      sql_mode=ORACLE will additionally support table%ROWTYPE variables as SELECT..INTO targets:

      SET sql_mode=ORACLE;
      DROP TABLE IF EXISTS t1;
      DROP PROCEDURE IF EXISTS p1;
      CREATE TABLE t1 (a INT, b VARCHAR(32));
      INSERT INTO t1 VALUES (10,'b10');
      DELIMITER $$
      CREATE PROCEDURE p1 AS
        rec1 t1%ROWTYPE;
      BEGIN
        SELECT * FROM t1 INTO rec1;
        SELECT rec1.a, rec1.b;
      END;
      $$
      DELIMITER ;
      CALL p1();
      

      +--------+--------+
      | rec1.a | rec1.b |
      +--------+--------+
      |     10 | b10    |
      +--------+--------+
      

      sql_mode=ORACLE will additionally support cursor%ROWTYPE variables as SELECT..INTO targets:

      SET sql_mode=ORACLE;
      DROP TABLE IF EXISTS t1;
      DROP PROCEDURE IF EXISTS p1;
      CREATE TABLE t1 (a INT, b VARCHAR(32));
      INSERT INTO t1 VALUES (10,'b10');
      DELIMITER $$
      CREATE PROCEDURE p1 AS
        CURSOR cur1 IS SELECT * FROM t1;
        rec1 cur1%ROWTYPE;
      BEGIN
        SELECT * FROM t1 INTO rec1;
        SELECT rec1.a, rec1.b;
      END;
      $$
      DELIMITER ;
      CALL p1();
      

      +--------+--------+
      | rec1.a | rec1.b |
      +--------+--------+
      |     10 | b10    |
      +--------+--------+
      

      An attempt to use multiple ROW variables in the SELECT..INTO list will report an error.

      An attempt to use ROW variables with a different column count than in the SELECT..INTO list will report an error.

        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: