在Oracle中,是否可以通过视图插入或更新记录?
在Oracle中,是否可以通过视图插入或更新一条记录(一行)?
In Oracle, is it possible to INSERT or UPDATE a record (a row) through a view?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Oracle 中的视图可能在特定条件下是可更新的。这可能很棘手,并且通常是不可取的。
来自 Oracle 10g SQL 参考
:可更新视图 可
更新视图是一种可用于插入、更新或删除基表行的视图。您可以创建本质上可更新的视图,也可以在任何视图上创建 INSTEAD OF 触发器以使其可更新。
要了解是否以及以何种方式可以修改本质上可更新视图的列,请查询 USER_UPDATABLE_COLUMNS 数据字典视图。该视图显示的信息仅对于本质上可更新的视图才有意义。对于本质上可更新的视图,必须满足以下条件:
此外,如果本质上可更新的视图包含伪列或表达式,则您无法使用引用任何这些伪列或表达式的 UPDATE 语句来更新基表行。
如果希望联接视图可更新,则必须满足以下所有条件:
Views in Oracle may be updateable under specific conditions. It can be tricky, and usually is not advisable.
From the Oracle 10g SQL Reference:
Notes on Updatable Views
An updatable view is one you can use to insert, update, or delete base table rows. You can create a view to be inherently updatable, or you can create an INSTEAD OF trigger on any view to make it updatable.
To learn whether and in what ways the columns of an inherently updatable view can be modified, query the USER_UPDATABLE_COLUMNS data dictionary view. The information displayed by this view is meaningful only for inherently updatable views. For a view to be inherently updatable, the following conditions must be met:
In addition, if an inherently updatable view contains pseudocolumns or expressions, then you cannot update base table rows with an UPDATE statement that refers to any of these pseudocolumns or expressions.
If you want a join view to be updatable, then all of the following conditions must be true:
Oracle 有两种不同的方法使视图可更新: -
我会远离替代触发器,并让您的代码直接更新基础表,而不是通过视图。
Oracle has two different ways of making views updatable:-
I would stay away from instead-of triggers and get your code to update the underlying tables directly rather than through the view.
有两种情况可以通过视图更新记录:
通常,您不应该依赖能够对视图执行插入,除非您专门为其编写了 INSTEAD OF 触发器。请注意,还可以编写 INSTEAD OF UPDATE 触发器来帮助执行更新。
There are two times when you can update a record through a view:
Generally, you should not rely on being able to perform an insert to a view unless you have specifically written an INSTEAD OF trigger for it. Be aware, there are also INSTEAD OF UPDATE triggers that can be written as well to help perform updates.
是,您可以更新并插入到视图中,并且该编辑将反映在原始表格上....
但是
1-视图应该具有表上的所有NOT NULL值
2-更新应具有与表相同的规则...“更新与其他外键相关的主键..等”...
YES, you can Update and Insert into view and that edit will be reflected on the original table....
BUT
1-the view should have all the NOT NULL values on the table
2-the update should have the same rules as table... "updating primary key related to other foreign key.. etc"...