- create table test1(t1id int primary key,t1v varchar2(10))
- create table test2(t2id int primary key,t2v varchar2(10))
- insert into test1 values(1,'t1');
- insert into test1 values(2,'t2');
- insert into test1 values(3,'t3');
- insert into test2 values(1,'t21');
- insert into test2 values(2,'t22');
- insert into test2 values(3,'t23');
- create view test1v
- as select t1id ,t1v,t2id,t2v
- from test1 join test2
- on test1.t1id=test2.t2id
select * from test1v

update test1v set t1v='t11'
update test1v set t2v='t22'
insert into test1v(t1id,t1v) values(4,'t4')
insert into test1v(t2id,t2v) values(4,'t24')
delete from test1v where t1id=4
delete from test1v where t2id=4(这两条delete语句都是将test1表中的数据delete了??)
但是下面的DML操作是不可以的:
update test1v set t1v='t11',t2v='t22'
insert into test1v values(5,'t5',5,'t25')
ORA-01776: cannot modify more than one base table through a join view
对于View是否可以进行DML操作还有一些其他限制:
不能有start with和connect by.
不能有group by和having.
不能有集合操作union,intersect和minus.
不能有聚合函数,如AVG,COUNT,MAX等等.
不能有rownum伪列.
当view有check option的时候:
- create view test1v
- as select t1id ,t1v,t2id,t2v
- from test1 join test2
- on test1.t1id=test2.t2id
- with check option
update test1v set t1id=4 where t1id=1
ORA-01733: virtual column not allowed here
如何查看那些字段可以插入更新
select * from USER_UPDATABLE_COLUMNS where table_name='TESTV'
更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12
