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

# Using Recursion with PL/SQL

If a subtype does not explicitly specify an AUTHID clause, it inherits the AUTHID of its supertype.

If a subtype does specify an AUTHID clause, its AUTHID must match the AUTHID of its supertype. Also, if the AUTHID is DEFINER, both the supertype and subtype must have been created in the same schema.

Calling Invoker's Rights Instance Methods

An invoker's rights instance method executes with the privileges of the invoker, not the creator of the instance. Suppose that Person is an invoker's rights object type, and that user SCOTT creates p1, an object of type Person. If user BLAKE calls instance method change_job to operate on object p1, the current user of the method is BLAKE, not SCOTT. Consider the following example:

-- user blake creates a definer-rights procedure

CREATE PROCEDURE reassign (p Person, new_job VARCHAR2) AS BEGIN

--user blake calls method change_job, so the

--method executes with the privileges of blake p.change_job(new_job);

...

END;

/

-- user scott passes a Person object to the procedure DECLARE

p1 Person; BEGIN

p1 := Person(...); blake.reassign(p1, 'CLERK');

...

END;

/

Using Recursion with PL/SQL

Recursion is a powerful technique for simplifying the design of algorithms. Basically, recursion means self-reference. In a recursive mathematical sequence, each term is derived by applying a formula to preceding terms. The Fibonacci sequence (0, 1, 1, 2, 3, 5, 8, 13, 21, ...), is an example. Each term in the sequence (after the second) is the sum of the two terms that immediately precede it.

In a recursive deﬁnition, something is deﬁned as simpler versions of itself. Consider the deﬁnition of n factorial (n!), the product of all integers from 1 to n:

n! = n * (n - 1)!

## What Is a Recursive Subprogram?

A recursive subprogram is one that calls itself. Each recursive call creates a new instance of any items declared in the subprogram, including parameters, variables, cursors, and exceptions. Likewise, new instances of SQL statements are created at each level in the recursive descent.

Be careful where you place a recursive call. If you place it inside a cursor FOR loop or between OPEN and CLOSE statements, another cursor is opened at each call, which might exceed the limit set by the Oracle initialization parameter OPEN_CURSORS.

8-20 PL/SQL User's Guide and Reference

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