Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
40
Добавлен:
16.04.2013
Размер:
4.96 Mб
Скачать

Calling Stored Functions from SQL Expressions

DECLARE

Tax_id NUMBER;

Income_tax NUMBER;

BEGIN

SELECT scott.tax_rate (Ss_no, Sal)

INTO Income_tax

FROM Tax_table

WHERE Ss_no = Tax_id;

END;

These sample calls to PL/SQL functions are allowed in SQL expressions:

Circle_area(Radius) Payroll.Tax_rate(Empno)

scott.Payroll.Tax_rate@boston_server(Dependents, Empno)

Arguments

To pass any number of arguments to a function, supply the arguments within the parentheses. You must use positional notation; named notation is not supported. For functions that do not accept arguments, use ().

Using Default Values

The stored function Gross_pay initializes two of its formal parameters to default values using the DEFAULT clause. For example:

CREATE OR REPLACE FUNCTION Gross_pay (Emp_id IN NUMBER,

St_hrs IN NUMBER DEFAULT 40,

Ot_hrs IN NUMBER DEFAULT 0) RETURN NUMBER AS

...

When calling Gross_pay from a procedural statement, you can always accept the default value of St_hrs. This is because you can use named notation, which lets you skip parameters. For example:

IF Gross_pay(Eenum, Ot_hrs => Otime) > Pay_limit

THEN ...

However, when calling Gross_pay from a SQL expression, you cannot accept the default value of St_hrs, unless you accept the default value of Ot_hrs. This is because you cannot use named notation.

Using Procedures and Packages 7-53

Соседние файлы в папке Oracle 10g