Previous |
Next |
A record is a PL/SQL composite variable that can store data values of different types, similar to a struct
type in C, C++, or Java. The internal components of a record are called fields. To access a record field, you use dot notation: record_name
.field_name
.
You can treat record fields like scalar variables. You can also pass entire records as subprogram parameters (if neither the sending nor receiving subprogram is a standalone subprogram).
Records are useful for holding data from table rows, or from certain columns of table rows. Each record field corresponds to a table column.
There are three ways to create a record:
Declare a RECORD
type, and then declare a variable of that type.
The syntax is:
TYPE record_name IS RECORD ( field_name data_type [:= initial_value] [, field_name data_type [:= initial_value ] ]... ); variable_name record_name;
Declare a variable of the type table_name
%ROWTYPE
.
The fields of the record have the same names and data types as the columns of the table.
Declare a variable of the type cursor_name
%ROWTYPE
.
The fields of the record have the same names and data types as the columns of the table in the FROM
clause of the cursor SELECT
statement.
Oracle Database PL/SQL Language Reference for more information about defining RECORD
types and declaring records of that type
Oracle Database PL/SQL Language Reference for the syntax of a RECORD
type definition
Oracle Database PL/SQL Language Reference for more information about the %ROWTYPE
attribute
Oracle Database PL/SQL Language Reference for the syntax of the %ROWTYPE
attribute