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

Calling Stored Functions from SQL Expressions

Privileges

To call a PL/SQL function from SQL, you must either own or have EXECUTE privileges on the function. To select from a view defined with a PL/SQL function, you must have SELECT privileges on the view. No separate EXECUTE privileges are necessary to select from the view.

Requirements for Calling PL/SQL Functions from SQL Expressions

To be callable from SQL expressions, a user-defined PL/SQL function must meet the following basic requirements:

It must be a stored function, not a function defined within a PL/SQL block or subprogram.

It must be a row function, not a column (group) function; in other words, it cannot take an entire column of data as its argument.

All its formal parameters must be IN parameters; none can be an OUT or IN OUT parameter.

The datatypes of its formal parameters must be Oracle built-in types, such as

CHAR, DATE, or NUMBER, not PL/SQL types, such as BOOLEAN, RECORD, or TABLE.

Its return type (the datatype of its result value) must be an Oracle built-in type. For example, the following stored function meets the basic requirements:

Note: You may need to set up the following data structures for certain examples to work:

CREATE TABLE Payroll(

 

Srate

NUMBER,

Orate

NUMBER,

Acctno

NUMBER);

 

 

 

 

CREATE FUNCTION Gross_pay

(Emp_id IN NUMBER,

St_hrs IN NUMBER DEFAULT 40,

Ot_hrs IN NUMBER DEFAULT 0) RETURN NUMBER AS

St_rate NUMBER;

Ot_rate NUMBER;

BEGIN

7-54 Oracle Database Application Developer's Guide - Fundamentals

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