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

Calling Stored Functions from SQL Expressions

The CONNECT BY, START WITH, ORDER BY, and GROUP BY clauses.

The VALUES clause of the INSERT statement.

The SET clause of the UPDATE statement.

You cannot call stored PL/SQL functions from a CHECK constraint clause of a CREATE or ALTER TABLE statement or use them to specify a default value for a column. These situations require an unchanging definition.

Note: Unlike functions, which are called as part of an expression, procedures are called as statements. Therefore, PL/SQL procedures are not directly callable from SQL statements. However, functions called from a PL/SQL statement or referenced in a SQL expression can call a PL/SQL procedure.

Syntax for SQL Calling a PL/SQL Function

Use the following syntax to reference a PL/SQL function from SQL:

[[schema.]package.]function_name[@dblink][(param_1...param_n)]

For example, to reference a function you created that is called My_func, in the My_ funcs_pkg package, in the Scott schema, that takes two numeric parameters, you could call the following:

SELECT Scott.My_funcs_pkg.My_func(10,20) FROM dual;

Naming Conventions

If only one of the optional schema or package names is given, then the first identifier can be either a schema name or a package name. For example, to determine whether Payroll in the reference Payroll.Tax_rate is a schema or package name, Oracle Database proceeds as follows:

Oracle Database first checks for the Payroll package in the current schema.

If the PAYROLL package is found in the current schema, then Oracle Database looks for a Tax_rate function in the Payroll package. If a Tax_rate function is not found in the Payroll package, then an error message is returned.

If a Payroll package is not found, then Oracle Database looks for a schema named Payroll that contains a top-level Tax_rate function. If the Tax_rate

Using Procedures and Packages 7-51

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