你好,游客 登录 注册 搜索
背景:
阅读新闻

什么是Oracle Key-Preserved Table和什么样的视图可以进行DML操作

[日期:2012-05-05] 来源:Linux公社  作者:kkdelta [字体:大 中 小]
一个View中可以有多个key preserved tables
  1. create table test1(t1id int primary key,t1v varchar2(10))  
  2. create table test2(t2id int primary key,t2v varchar2(10))  
  3.   
  4. insert into test1 values(1,'t1');  
  5. insert into test1 values(2,'t2');  
  6. insert into test1 values(3,'t3');  
  7.   
  8. insert into test2 values(1,'t21');  
  9. insert into test2 values(2,'t22');  
  10. insert into test2 values(3,'t23');  
  11.   
  12. create view test1v   
  13. as select t1id ,t1v,t2id,t2v  
  14. from test1 join test2  
  15. on test1.t1id=test2.t2id  

在这个视图中,test1,test2都是key preserved table.但是对view的DML操作一次只能作用于一个表,不能同时对多个base 表操作.
select * from test1v


如下面的DML是可以的
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的时候:
  1. create view test1v   
  2. as select t1id ,t1v,t2id,t2v  
  3. from test1 join test2  
  4. on test1.t1id=test2.t2id  
  5. with check option  
insert into test1v(t1id,t1v) values(4,'t4')
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

linux
相关资讯       Oracle基础教程 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款