PL/SQL parser (MDEV-10142)

[MDEV-14139] Anchored data types for variables Created: 2017-10-26  Updated: 2023-05-12  Resolved: 2017-10-27

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

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

Issue Links:
Blocks
blocks MDEV-13418 Compatibility: The order of evaluatio... Stalled
Relates
relates to MDEV-31250 ROW variables do not get assigned fro... Closed
relates to MDEV-10577 sql_mode=ORACLE: %TYPE in variable d... Closed
relates to MDEV-14212 Add Field_row for SP ROW variables Closed
Sprint: 10.2.2-3, 10.2.2-1, 10.2.2-2, 10.2.2-4, 10.1.18

 Description   

Previously we added anchored data type declarations for table columns, tables, cursors:

DECLARE a TYPE OF t1.a;   -- table column
DECLARE b ROW TYPE OF t1; -- table row
DECLARE c ROW TYPE OF c1; -- cursor row

Under terms of this tasks we'll add anchor references to other variables:

DECLARE var1 INT;
DECLARE var2 TYPE OF var1;

The following features will be supported:

  • Nested anchor declarations (anchors to anchors)
  • Anchors to implicit ROW variables
  • Anchors to table and cursor ROW variables
  • Only local SP variables will be supported (SP parameters and SP return values are out of scope of this task)
  • Both TYPE OF (for sql_mode=default) and %TYPE (for sql_mode=ORACLE) will be supported

Example: Scalar declarations

DECLARE var1 INT;
DECLARE var2 TYPE OF var1;
DECLARE var3 TYPE OF var2;

Example: Scalar declarations for sql_mode=ORACLE

DECLARE
  var1 INT;
  var2 var1%TYPE;
  var3 var2%TYPE;

Example: Implicit ROW variables

DECLARE row1 ROW (a INT, b TEXT);
DECLARE row2 TYPE OF row1;

Example: Implicit ROW variables for sql_mode=ORACLE

DECLARE
  row1 ROW (a INT, b TEXT);
  row2 row1%TYPE;

Example: Table ROW variables

DECLARE row1 ROW TYPE OF table1;
DECLARE row2 TYPE OF row1;

Example: Table ROW variables for sql_mode=ORACLE

DECLARE
  row1 ROW TYPE OF table1;
  row2 row1%TYPE;

Example: Cursor ROW variables

DECLARE CURSOR cur1 AS SELECT 10 AS a, 'b' AS b;
DECLARE row1 ROW TYPE OF cur1;
DECLARE row2 TYPE OF row1;

Example: Cursor ROW variables for sql_mode=ORACLE

DECLARE
  CURSOR cur1 AS SELECT 10 AS a, 'b' AS b;
  row1 cur1%ROWTYPE;
  row2 row1%TYPE;


Generated at Thu Feb 08 08:11:13 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.