Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Semestr2 / 1 - Oracle / PL_SQL / b14261.pdf
Скачиваний:
27
Добавлен:
12.05.2015
Размер:
4.36 Mб
Скачать

Using Invoker's Rights Versus Definer's Rights (AUTHID Clause)

owner of that subprogram becomes the current user. The current user might change as new subprograms are called or as subprograms exit.

To verify who the current user is at any time, you can check the USER_USERS data dictionary view. Inside an invoker's rights subprogram, the value from this view might be different from the value of the USER built-in function, which always returns the name of the session user.

How External References Are Resolved in Invoker's Rights Subprograms

If you specify AUTHID CURRENT_USER, the privileges of the current user are checked at run time, and external references are resolved in the schema of the current user. However, this applies only to external references in:

SELECT, INSERT, UPDATE, and DELETE data manipulation statements

The LOCK TABLE transaction control statement

OPEN and OPEN-FOR cursor control statements

EXECUTE IMMEDIATE and OPEN-FOR-USING dynamic SQL statements

SQL statements parsed using DBMS_SQL.PARSE()

For all other statements, the privileges of the owner are checked at compile time, and external references are resolved in the schema of the owner. For example, the assignment statement in Example 8–14 refers to the packaged function num_above_salary in the emp_actions package in Example 1–13 on page 1-14. This external reference is resolved in the schema of the owner of procedure above_salary.

Example 8–14 Resolving External References in an Invoker's Rights Subprogram

CREATE PROCEDURE above_salary (emp_id IN NUMBER) AUTHID CURRENT_USER AS

emps NUMBER; BEGIN

emps := emp_actions.num_above_salary(emp_id); DBMS_OUTPUT.PUT_LINE( 'Number of employees with higher salary: ' ||

TO_CHAR(emps));

END;

/

CALL above_salary(120);

The Need for Template Objects in Invoker's Rights Subprograms

The PL/SQL compiler must resolve all references to tables and other objects at compile time. The owner of an invoker's rights subprogram must have objects in the same schema with the right names and columns, even if they do not contain any data. At run time, the corresponding objects in the caller's schema must have matching definitions. Otherwise, you get an error or unexpected results, such as ignoring table columns that exist in the caller's schema but not in the schema that contains the subprogram.

Overriding Default Name Resolution in Invoker's Rights Subprograms

Occasionally, you might want an unqualified name to refer to some particular schema, not the schema of the caller. In the same schema as the invoker's rights subprogram, create a public synonym for the table, procedure, function, or other object using the

CREATE SYNONYM statement:

Using PL/SQL Subprograms 8-17

Соседние файлы в папке PL_SQL