This article presents how to execute DML operations on complex views using INSTEAD OF triggers that otherwise could not be done.
Update/Insert/Delete via view is possible in Oracle.
create table test_tbl
(
id number,
id1 number,
id2 number
);
create view test_vw
as
select * from test_tbl;
INSERT, UPDATE, DELETE
insert into test_vw values(1,1,1);
insert into test_vw values(2,2,2);
insert into test_vw values(3,3,3);
commit;
update test_vw
set id2=4
where id1=3;
commit;
delete from test_vw
where id=2;
commit;
select * from test_vw;
ID ID1 ID2
---------- ---------- ----------
1 1 1
3 3 4
but with many exceptions
The view must not contain any of the following constructs:
- A set operator
- A DISTINCT operator
- An aggregate or analytic function
- A GROUP BY, ORDER BY, MODEL, CONNECT BY, or START WITH clause
- A collection expression in a SELECT list
- A subquery in a SELECT list
- A subquery designated WITH READ ONLY
and many many others – more you can read in Oracle documentation. If view violates one of above rule then it’s called complex view.
Continue reading →