Introduction to PL/SQL record records

Source: Internet
Author: User

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;/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.