ROW

ROW is a data type used in stored programs to store a complete row of data from a cursor or table.

Syntax

ROW (<field name> <data type> [{, <field name> <data type>}... ])

Description

ROW is a data type for stored procedure variables.

Features

ROW fields as normal variables

ROW fields (members) act as normal variables, and are able to appear in all query parts where a stored procedure variable is allowed:

  • Assignment is using the := operator and the SET command:

a.x:= 10;
a.x:= b.x;
SET a.x= 10, a.y=20, a.z= b.z;
  • Passing to functions and operators:

SELECT f1(rec.a), rec.a<10;
  • Clauses (select list, WHERE, HAVING, LIMIT, etc...,):

  • INSERT values:

  • SELECT .. INTO targets:

ROW type variables as FETCH targets

ROW type variables are allowed as FETCH targets:

where cur is a CURSOR and rec is a ROW type stored procedure variable.

Note, currently an attempt to use FETCH for a ROW type variable returns this error:

FETCH from a cursor cur into a ROW variable rec works as follows:

  • The number of fields in cur must match the number of fields in rec. Otherwise, an error is reported.

  • Assignment is done from left to right. The first cursor field is assigned to the first variable field, the second cursor field is assigned to the second variable field, etc.

  • Field names in rec are not important and can differ from field names in cur.

See FETCH Examples (below) for examples of using this withsql_mode=ORACLE and sql_mode=DEFAULT.

ROW type variables as SELECT...INTO targets

ROW type variables are allowed as SELECT..INTO targets with some differences depending on which sql_mode is in use.

  • When using sql_mode=ORACLE, table%ROWTYPE and cursor%ROWTYPE variables can be used as SELECT...INTO targets.

  • Using multiple ROW variables in the SELECT..INTO list will report an error.

  • Using ROW variables with a different column count than in the SELECT..INTO list will report an error.

See SELECT...INTO Examples (below) for examples of using this with sql_mode=ORACLE and sql_mode=DEFAULT.

Features not implemented

The following features are planned, but not implemented yet:

  • Returning a ROW type expression from a stored function (see MDEV-12252). This will need some grammar change to support field names after parentheses:

  • Returning a ROW type expression from a built-in hybrid type function, such as CASE, IF, etc.

  • ROW of ROW values

Examples

Declaring a ROW in a stored procedure

FETCH Examples

A complete FETCH example for sql_mode=ORACLE:

A complete FETCH example for sql_mode=DEFAULT:

SELECT...INTO Examples

A SELECT...INTO example for sql_mode=DEFAULT:

The above example returns:

A SELECT...INTO example for sql_mode=ORACLE:

The above example returns:

An example for sql_mode=ORACLE using table%ROWTYPE variables as SELECT..INTO targets:

The above example returns:

An example for sql_mode=ORACLE using cursor%ROWTYPE variables as SELECT..INTO targets:

The above example returns:

Row Table example:

See Also

This page is licensed: CC BY-SA / Gnu FDL

Last updated

Was this helpful?