background image
<< Using Composite Data Structures | Using a RECORD Datatype >>
<< Using Composite Data Structures | Using a RECORD Datatype >>

Creating a RECORD Datatype

Using Composite Data Structures; Records
4-30 Oracle Database 2 Day Developer's Guide
table columns. The record structure is very efficient for passing related items to a
subprogram as a single parameter, and for effectively using related fields from
different tables during run time.
You must define a
RECORD
as a type, and access its fields through the point notation.
The general form for defining and using a record follows:
TYPE
record_name
IS RECORD( -- define record type
field_1
data_type
, -- define fields in record
...
field_n
data_type
);
...
variable_name record_name
; -- define variable of new type
...
BEGIN
...
...
variable_name.field1
...; -- use fields of new variable
...
variable_name.fieldn
...;
...
END...;
In the
eval_frequency
function from
"Using the LOOP...EXIT WHEN"
on page 4-28,
you used several related parameters. You can use the
RECORD
construct to combine
some of these items into a single parameter.
You will create a type that will contain the upper and lower limits for a job
specification.
To create a RECORD type:
1.
In the Connections navigation hierarchy, click the plus sign (+) beside Packages to
expand the group.
2.
Right-click EMP_EVAL.
3.
Select Edit.
The
emp_eval
pane appears. It shows the specification of the
emp_eval
package.
4.
In the
emp_eval
package specification, immediately before the closing line of the
package specification,
END emp_eval
, enter the definition of a record type
sal_
info
, which contains the fields necessary for evaluating salary levels.
TYPE sal_info IS RECORD -- type for salary, limits, raises, and adjustments
( job_id jobs.job_id%type
, sal_min jobs.min_salary%type
, sal_max jobs.max_salary%type
, salary employees.salary%type
, sal_raise NUMBER(3,3) );
5.
Compile and save
emp_eval
.
The following message appears in the Messages-Log pane:
EMP_EVAL Compiled
Once you declare a new
RECORD
type in the package specification, you can use it
inside the package body to declare variables of that type. You will create a new
procedure,
salary_schedule
, and invoke it from the
eval_frequency
function
using a variable of type
sal_info
.
Note that PL/SQL compilation is a single path process; if a subprogram is declared
after its client subprogram, PL/SQL compiler throws an error. To work around this