Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to insert values in a view created on multiple tables

672689Jun 4 2009 — edited Jun 7 2009
Hi all,

My aim to insert values in a view
So for that i have created a trigger
then i tryed to insert the value in the view, im getting as row inserted but the value is not getting inserted

here are the steps i followed:


SQL> create table a(x int primary key)
2 /

Table created.

SQL> create table b(x references a,y varchar2(30))
2 /

Table created.

SQL> insert into a values(1)
2 /

1 row created.

SQL> insert into b values(1,'One')
2 /

1 row created.

SQL> create or replace view v
2 as
3 select a.x,b.x as b_x,y from a,b where a.x = b.x
4 /

View created.

SQL> select * from v
2 /

X B_X Y
---------- ---------- ------------------------------
1 1 One

SQL> create or replace trigger v_t
2 instead of insert on v
3 for each row
4 begin
5 if :old.x <> :new.x then
6 insert into a values(:new.x);
7 end if;
8 if :old.b_x <> :new.b_x then
9 insert into b values(:new.b_x,:new.y);
10 end if;
11* end;
SQL> /

Trigger created.

SQL> insert into v values(20,20,'Twenty')
2 /

1 row created.

SQL> select * from v
2 /

X B_X Y
---------- ---------- ------------------------------
1 1 One


Can any one suggest me a valid query to insert data into a view which is created on multiple tables.

Thanks in advance,
Shalini
This post has been answered by Hoek on Jun 5 2009
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 5 2009
Added on Jun 4 2009
3 comments
965 views