Добавил:
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)

Using Object Types with Invoker's Rights Subprograms

To define object types for use in any schema, specify the AUTHID CURRENT_USER clause. For information on object types, see Oracle Database Application Developer's Guide - Object-Relational Features.

Suppose user HR creates the following object type:

Example 8–15 Creating an Object Type With AUTHID CURRENT USER

CREATE TYPE person_typ AUTHID CURRENT_USER AS OBJECT ( person_id NUMBER,

person_name VARCHAR2(30), person_job VARCHAR2(10),

STATIC PROCEDURE new_person_typ (

person_id NUMBER, person_name VARCHAR2, person_job VARCHAR2, schema_name VARCHAR2, table_name VARCHAR2),

MEMBER PROCEDURE change_job (SELF IN OUT NOCOPY person_typ, new_job VARCHAR2) );

/

CREATE TYPE BODY person_typ AS STATIC PROCEDURE new_person_typ (

person_id NUMBER, person_name VARCHAR2, person_job VARCHAR2, schema_name VARCHAR2, table_name VARCHAR2) IS

sql_stmt VARCHAR2(200); BEGIN

sql_stmt := 'INSERT INTO ' || schema_name || '.'

|| table_name || ' VALUES (HR.person_typ(:1, :2, :3))';

EXECUTE IMMEDIATE sql_stmt USING person_id, person_name, person_job; END;

MEMBER PROCEDURE change_job (SELF IN OUT NOCOPY person_typ, new_job VARCHAR2) IS BEGIN

person_job := new_job; END;

END;

/

Then, user HR grants the EXECUTE privilege on object type person_typ to user OE:

GRANT EXECUTE ON person_typ TO OE;

Finally, user OE creates an object table to store objects of type person_typ, then calls procedure new_person_typ to populate the table:

CONNECT oe/oe;

CREATE TABLE person_tab OF hr.person_typ;

BEGIN

hr.person_typ.new_person_typ(1001, 'Jane Smith', 'CLERK', 'oe', 'person_tab'); hr.person_typ.new_person_typ(1002, 'Joe Perkins', 'SALES','oe', 'person_tab'); hr.person_typ.new_person_typ(1003, 'Robert Lange', 'DEV','oe', 'person_tab');

END;

/

The calls succeed because the procedure executes with the privileges of its current user (OE), not its owner (HR).

For subtypes in an object type hierarchy, the following rules apply:

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

8-20 Oracle Database PL/SQL User’s Guide and Reference

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