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

Creating Triggers

Triggers on Nested Table View Columns

INSTEAD OF triggers can also be created over nested table view columns. These triggers provide a way of updating elements of the nested table. They fire for each nested table element being modified. The row correlation variables inside the trigger correspond to the nested table element. This type of trigger also provides an additional correlation name for accessing the parent row that contains the nested table being modified.

Note: These triggers:

Can only be defined over nested table columns in views.

Fire only when the nested table elements are modified using the THE() or TABLE() clauses. They do not fire when a DML statement is performed on the view.

For example, consider a department view that contains a nested table of employees.

CREATE OR REPLACE VIEW Dept_view AS

SELECT d.Deptno, d.Dept_type, d.Dept_name,

CAST (MULTISET ( SELECT e.Empno, e.Empname, e.Salary)

FROM Emp_tab e

WHERE e.Deptno = d.Deptno) AS Amp_list_ Emplist

FROM Dept_tab d;

The CAST (MULTISET..) operator creates a multi-set of employees for each department. If you want to modify the emplist column, which is the nested table of employees, then you can define an INSTEAD OF trigger over the column to handle the operation.

The following example shows how an insert trigger might be written:

CREATE OR REPLACE TRIGGER Dept_emplist_tr

INSTEAD OF INSERT ON NESTED TABLE Emplist OF Dept_view

REFERENCING NEW AS Employee

PARENT AS Department

FOR EACH ROW

BEGIN

--The insert on the nested table is translated to an insert on the base table:

INSERT INTO Emp_tab VALUES (

:Employee.Empno, :Employee.Empname,:Employee.Salary, :Department.Deptno);

END;

9-12 Oracle Database Application Developer's Guide - Fundamentals

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