Paassing Values To Record Type
When you assign values to a record, you actually assign values to the fields within it.
The General Syntax to assign a value to a column within a record direclty is:
record_name.col_name := value;
If you used %ROWTYPE to declare a record, you can assign values as shown:
record_name.column_name := value;
We can assign values to records using SELECT Statements as shown:
SELECT col1, col2
INTO record_name.col_name1, record_name.col_name2
FROM table_name
[WHERE clause];
If %ROWTYPE is used to declare a record then you can directly assign values to the whole record instead of each columns separately. In this case, you must SELECT all the columns from the table into the record as shown:
SELECT * INTO record_name
FROM table_name
[WHERE clause];
Reading From Record
Lets see how we can get values from a record. The General Syntax to retrieve a value from a specific field into another variable is:
var_name := record_name.col_name;
The following are consolidates the different ways you can assign values to and from a record:
- To directly assign a value to a specific column of a record.
record_name.col_name := value;
- To directly assign a value to a specific column of a record, if the record is declared using %ROWTYPE.
record_name.column_name := value;
- To assign values to each field of a record from the database table.
SELECT col1, col2 INTO record_name.col_name1, record_name.col_name2 FROM table_name [WHERE clause];
- To assign a value to all fields in the record from a database table.
SELECT * INTO record_name FROM table_name [WHERE clause];
- To get a value from a record column and assigning it to a variable.
variable_name := record_name.col_name;