ORA-01779问题的解决

昨天帮一个师弟看一个ORACLE触发器T的问题,这个触发器建在视图V上,当用户往视图里插记录的时候就自动插到视图的组成表里。但是每次插入总提示,ORA-01779 cannot modify a column which maps to a non key-preserved table。而怪异的是,有一个视图V2和V的构成方式一摸一样,但是它的触发器T2就没问题。在网上找了很多帖子,绝大部分原因都是插入的基本表记录不唯一,我检查了触发器内容和基本表的keys,都没问题。

到第二天的时候突然看到一个帖子的原因解释:

view的更改是有限制的

General Rule
Any INSERT, UPDATE, or DELETE operation on a join view can modify only one underlying base table at a time.

UPDATE Rule
All updatable columns of a join view must map to columns of a key-preserved table. If the view is defined with the WITH CHECK OPTION clause, then all join columns and all columns of repeated tables are non-updatable.

DELETE Rule
Rows from a join view can be deleted as long as there is exactly one key-preserved table in the join. If the view is defined with the WITH CHECK OPTION clause and the key preserved table is repeated, then the rows cannot be deleted from the view.

INSERT Rule
An INSERT statement must not explicitly or implicitly refer to the columns of a non-key preserved table. If the join view is defined with the WITH CHECK OPTION clause, INSERT statements are not permitted.

( http://www.itpub.net/225291.html)

再检查了触发器,发现事件那块只关联了UPDATE,其他都没关联,粗心啊。全部关联上就好了。

看来触发器的几个选项一定要好好检查啊。

你可能感兴趣的:(ORA-01779问题的解决)