Test

Page 66

are three types of records: table-based, cursor-based, and programmer-defined.

Declaring Records Define and declare records either in the declaration section of a PL/SQL block or globally, via a package specification. You do not have to explicitly define table-based or cursorbased records, as they are implicitly defined with the same structure as a table or a cursor. Variables of these types are declared via the %ROWTYPE attribute. The record’s fields correspond to the table’s columns or the columns in the SELECT list. For example: DECLARE -- Declare table-based record for company table. comp_rec company%ROWTYPE CURSOR comp_summary_cur IS SELECT c.company_id,SUM(s.gross_sales) gross FROM company c ,sales s WHERE c.company_id = s.company_id; -- Declare a cursor-based record. comp_summary_rec comp_summary_cur%ROWTYPE;

Programmer-defined records must be explicitly defined with the TYPE statement in the PL/SQL declaration section or in a package specification. Variables of this type then can be declared as shown here: DECLARE TYPE name_rectype IS RECORD( prefix VARCHAR2(15) ,first_name VARCHAR2(30) ,middle_name VARCHAR2(30) ,sur_name VARCHAR2(30) ,suffix VARCHAR2(10) ); TYPE employee_rectype IS RECORD ( emp_id NUMBER(10) NOT NULL ,mgr_id NUMBER(10) ,dept_no dept.deptno%TYPE

Records in PL/SQL

|

57


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.