Oracle PL/SQL Records

Table Based Records

You define and declare records either in the declaration section of a PL/SQL block, or globally, via a package specification.

%TYPE and %ROWTYPE

%TYPE is used to declare a variable that is of the same type as a specified table’s column.

Emp_number emp.empno%type;

%ROWTYPE is used to declare a record(variable that represents the entire row of a table).

Emp_record emp%rowtype

Declare table-based record for employee table.

emp_rec employee%ROWTYPE

Cursor Based Records

CURSOR c IS

SELECT beer, price

FROM Sells

WHERE bar = 'Joe''s bar';

Bp1 c%ROWTYPE;


Programmer Defined Records

It is a collection of variables:

Type my_first_record is record (

Name varchar2(20);

Age number;

Salary number;

);

Var_of_myfirstrecord my_first_record;

Important points on records

1) Individual fields are referenced via dot notation:

record_name.field_name

Example:

Emp_rec.first_name

2) Individual fields within a record can be read from or written to. They can appear on either the left or right side of the assignment operator:

BEGIN

policy_start_date:= new_emp_rec.hire_date + 30;

new_emp_rec.present:= FALSE;

Recent Tutorials