The record type is a mirror image of the row data structure in the table. Each record stores only one row of data, and the record contains the fields, not the columns.
1. Implicitly define record types with the%rowtype attribute
DeclareIndividual Individuals%RowType--record variable individual is mirrored with the structure of the individuals table, owning all the fields of the tablebeginindividual.individual_id:=1;--Initialize individual fields of a variableIndividual_id.first_name:='Jone'; Individual_id.last_name:='Steve'; Insert intoIndividuals--insert a field into the individuals tablevaules (individual.individual_id, Individual_id.first_name, individual_id.last_name); Commit; End; /
2. Explicitly define a record as a PL/SQL record type
Declaretype Individual_record isRecord--the definition record type of the explicit Shi Individual_record(individual_idinteger, first_namevarchar( - Char), last_namevarchar( - Char) );beginindividual Individual_record; --define a variable for Individual_record individualINDIVIDUAL.INDIVIDUAL_ID:=1;--Initialize individual fields of a variableIndividual_id.first_name:='Jone'; Individual_id.last_name:='Steve'; Insert intoIndividuals--insert a field into the individuals tablevaules (individual.individual_id, Individual_id.first_name, individual_id.last_name);CommitEnd;/
3. Explicitly define a record type as an object type
--Create a Database object typeCreate or ReplaceType Individual_record asObject--Object Type Header(individual_id interger, first_namevarchar( - Char), last_namevarchar( - Char), constructorfunctionIndividual_record (individual_id interger, first_namevarchar, Last_Namevarchar ) returnSelf asresult) instantiable notfinal;/--crate a Database object body--Object BodyCreate or ReplaceType Body Individual_record asConstructorfunctionIndividual_record (individual_id interger, first_namevarchar, Last_Namevarchar ) returnSelf asResult is --Constructor Implementation beginself.individual_id:=individual_id; Self.first_name:=first_name; Selg.last_name:=last_name; return; End;End;/Declareindividual Individual_record; --defining individual record variables with object typesbeginIndividual:=Individual (1,'Jone','Steve');--Call constructor to initialize record variable Insert intoIndividuals--insert a field into the individuals tablevaules (individual.individual_id, Individual_id.first_name, individual_id.last_name); Commit;End;/