PL/SQL parser - Phase 2 (MDEV-10764)

[MDEV-10592] sql_mode=ORACLE: TYPE .. TABLE OF for scalar data types Created: 2016-08-18  Updated: 2022-05-28

Status: Open
Project: MariaDB Server
Component/s: OTHER
Affects Version/s: None
Fix Version/s: None

Type: Technical task Priority: Major
Reporter: Alexander Barkov Assignee: Unassigned
Resolution: Unresolved Votes: 5
Labels: Compatibility, Oracle

Issue Links:
Blocks
is blocked by MDEV-4912 Data type plugin API version 1 Closed
Relates
relates to MDEV-10593 sql_mode=ORACLE: TYPE .. AS OBJECT: b... Open

 Description   

Add support for TABLE OF data type declaration, for scalar data types.

If TYPE declaration appears in AS or DECLARE section of a stored routine, then the data type is created temporary.
A CREATE TYPE statement creates types permanently.

The below example:

  • Declares a data type table_of_int_t as TABLE OF INT
  • Declares a table variable tbl of this type
  • Loads data from the table t1 into the table variable tbl
  • Appends one more record to tbl using methods tbl.extend and tbl.count
  • Iterates through all records in tbl and inserts data into t2

DROP TABLE t1;
CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (10);
INSERT INTO t1 VALUES (20);
DROP TABLE t2;
CREATE TABLE t2 (a INT);
DROP PROCEDURE p1;
CREATE PROCEDURE p1
AS
  TYPE table_of_int_t IS TABLE OF INT;
  tbl table_of_int_t;
BEGIN
  SELECT * BULK COLLECT INTO tbl FROM t1;
  tbl.extend;
  tbl(tbl.count):=1;
 
  FOR Y IN 1 .. tbl.count
  LOOP
    EXECUTE IMMEDIATE 'INSERT INTO t2 VALUES(:param)' USING tbl(Y)+1;
  END LOOP;
END;
/
CALL p1();
SELECT * FROM t2;

	 A
----------
	11
	21
	 2

Passing TABLE-type values to stored procedures

DROP PACKAGE g1;
DROP TABLE t1;
CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (1);
CREATE PACKAGE g1 IS
TYPE table_t IS TABLE OF INT;
PROCEDURE consume(t IN table_t);
PROCEDURE test_t;
END;
/
CREATE PACKAGE BODY g1 IS
PROCEDURE consume(t IN table_t) IS
BEGIN
FOR c IN 1 .. t.count
LOOP
EXECUTE IMMEDIATE 'INSERT INTO t1 VALUES(:p1)' USING t(c);
END LOOP;
NULL;
END;
PROCEDURE test_t IS
t table_t;
BEGIN
SELECT * BULK COLLECT INTO t FROM t1;
consume(t);
END;
END;
/
CALL g1.test_t();
SELECT * FROM t1;

 

	 A B
---------- --------------------
	 1 b
	 2 bb



 Comments   
Comment by Vamsi Krishna Maddi [ 2017-02-20 ]

Attached contains sample procedure using table of scalar data type.

Comment by Vamsi Krishna Maddi [ 2017-02-20 ]

The attached file has been deleted and sent to the respective engineer via email.

Comment by Elena Stepanova [ 2017-04-23 ]

Should probably be 10.3

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