background image
<< Using the %TYPE Attribute | Assigning Values from the Database >>
<< Using the %TYPE Attribute | Assigning Values from the Database >>

Assigning Values to Variables

Using Variables and Constants
Developing and Using Stored Procedures 4-19
EMP_EVAL Body Compiled
To use the %ROWTYPE attribute:
Look at the code used in the
eval_department
procedure in
"Using Explicit Cursors"
on page 4-33.
Assigning Values to Variables
You can assign values to a variable in three general ways: through the assignment
operator, by selecting a value into the variable, or by binding a variable. This section
covers the first two methods. Variable binding is described in 2 Day + guides for
Application Express, Java, .NET, and PHP.
Assigning Values with the Assignment Operator
You can assign values to a variable both in the declaration and the body of a
subprogram.
The following code shows the standard declaration of variables and constants. In
procedures and functions, the declaration block does not use the
DECLARE
keyword;
instead, it follows the
AS
keyword of the subprogram definition.
Example 4­2 Assigning variable values in a declaration
In the
emp_eval
Body pane, modify function
calculate_score
by adding a new
variable
running_total
. The value of
running_total
is also the new return value
of the function. You will set the initial value of the return variable to
0
. Note that
running_total
is declared as a general
NUMBER
because it will hold a product of
two
NUMBERs
with different precision and scale. New code is bold font.
FUNCTION calculate_score(evaluation_id IN scores.evaluation_id%TYPE
, performance_id IN scores.performance_id%TYPE)
RETURN NUMBER AS
n_score scores.score%TYPE; -- from SCORES
n_weight performance_parts.weight%TYPE; -- from PERFORMANCE_PARTS
running_total NUMBER := 0; -- used in calculations
max_score CONSTANT scores.score%TYPE := 9; -- a constant limit check
max_weight CONSTANT performance_parts.weight%TYPE:= 1;
-- a constant limit check
BEGIN
RETURN
running_total
;
END calculate_score;
Compile the
emp_eval
Body.
See Also:
Oracle Database PL/SQL Language Reference
See Also:
Oracle Database PL/SQL Language Reference
Oracle Database 2 Day + .NET Developer's Guide
Oracle Database 2 Day + PHP Developer's Guide
Oracle Database 2 Day + Java Developer's Guide.
Oracle Database 2 Day + Application Express Developer's Guide