Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Semestr2 / 1 - Oracle / PL_SQL / b14261.pdf
Скачиваний:
27
Добавлен:
12.05.2015
Размер:
4.36 Mб
Скачать

Passing Parameters to PL/SQL Subprograms

END;

/

Passing Parameters to PL/SQL Subprograms

This section explains how to pass information in and out of PL/SQL subprograms using parameters:

Actual Versus Formal Subprogram Parameters

Using Positional, Named, or Mixed Notation for Subprogram Parameters

Specifying Subprogram Parameter Modes

Using Default Values for Subprogram Parameters

Actual Versus Formal Subprogram Parameters

Subprograms pass information using parameters:

The variables declared in a subprogram specification and referenced in the subprogram body are formal parameters.

The variables or expressions passed from the calling subprogram are actual parameters.

A good programming practice is to use different names for actual and formal parameters.

When you call a procedure, the actual parameters are evaluated and the results are assigned to the corresponding formal parameters. If necessary, before assigning the value of an actual parameter to a formal parameter, PL/SQL converts the datatype of the value. For example, if you pass a number when the procedure expects a string, PL/SQL converts the parameter so that the procedure receives a string.

The actual parameter and its corresponding formal parameter must have compatible datatypes. For instance, PL/SQL cannot convert between the DATE and NUMBER datatypes, or convert a string to a number if the string contains extra characters such as dollar signs.

The procedure in Example 8–4 declares two formal parameters named emp_id and amount and the procedure call specifies actual parameters emp_num and bonus.

Example 8–4 Formal Parameters and Actual Parameters

DECLARE

emp_num

NUMBER(6) := 120;

bonus

NUMBER(6) := 100;

merit

NUMBER(4) := 50;

PROCEDURE raise_salary (emp_id NUMBER, amount NUMBER) IS BEGIN

UPDATE employees SET salary = salary + amount WHERE employee_id = emp_id; END raise_salary;

BEGIN

raise_salary(emp_num, bonus); -- procedure call specifies actual parameters raise_salary(emp_num, merit + bonus); -- expressions can be used as parameters

END;

/

8-6 Oracle Database PL/SQL User’s Guide and Reference

Соседние файлы в папке PL_SQL