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

Calling Stored Functions from SQL Expressions

function is not found in the Payroll schema, then an error message is returned.

You can also refer to a stored top-level function using any synonym that you have defined for it.

Name Precedence

In SQL statements, the names of database columns take precedence over the names of functions with no parameters. For example, if schema Scott creates the following two objects:

CREATE TABLE Emp_tab(New_sal NUMBER ...);

CREATE FUNCTION New_sal RETURN NUMBER IS ...;

Then, in the following two statements, the reference to New_sal refers to the column Emp_tab.New_sal:

SELECT New_sal FROM Emp_tab;

SELECT Emp_tab.New_sal FROM Emp_tab;

To access the function new_sal, enter the following:

SELECT Scott.New_sal FROM Emp_tab;

Example of Calling a PL/SQL Function from SQL For example, to call the Tax_rate

PL/SQL function from schema Scott, run it against the Ss_no and sal columns in Tax_table, and place the results in the variable Income_tax, specify the following:

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

CREATE TABLE Tax_table (

Ss_no NUMBER,

Sal NUMBER);

CREATE OR REPLACE FUNCTION tax_rate (ssn IN NUMBER, salary IN NUMBER) RETURN NUMBER IS

sal_out NUMBER; BEGIN

sal_out := salary * 1.1; END;

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

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