Friday 15 May 2015

INSTEAD OF TRIGGER TO MODIFY VIEW in PLSQL

INSTEAD OF TRIGGER is used to perform DML Operations on Views. Normally we cannot perform DML Operations on views.

Let us look in detail:
Create 2 Tables which consists id,name and place
(To copy the code select ctrl+C)


Create a view that is based on above 2 tables


Try to insert data to the view instead_trig_test_v.


It will not allow to insert data to the view and gives below error






You can insert data to the view by creating INSTEAD OF Trigger.


Insert a row to the view
 

The row will be inserted successfully to the view.
You can use the same for UPDATE and DELETE

For INSTEAD OF INSERT triggers to work on views, there are certain restrictions:

The view must not contain any of the following constructs:
1) A set operator
2) A DISTINCT operator
3) An aggregate or analytic function
4) A GROUP BY, ORDER BY, MODEL, CONNECT BY, or START WITH clause
5) A collection expression in a SELECT list
6) A subquery in a SELECT list
7) A subquery designated WITH READ ONLY
8) Joins, with some exceptions.
For more details refer Oracle Database Administrator's Guide

No comments: