oracle:为什么我不能插入视图
我创建了一个简单的视图,其中包含单个表中的列。当我尝试将值插入表中时,出现 ORA_01732 错误,表明 dml 在此视图上不合法。我确实在视图定义中有一个 order by 子句,我收集的视图定义不允许它本质上可更新,而且我发现我可能必须在视图定义中使用 INSTEAD OF 类型子句。有人可以告诉我如何构建可更新的视图吗?
这是创建视图语句:
create view CUST_VIEW
as select customer#,firstname,lastname,state
from book_customer
order by state, lastname;
I created a simple view with columns from a single table. When i try to insert values into the table, i get the ORA_01732 error that dml is not legal on this view. I DO have an order by clause in the view definition which I've gathered is not allowed for it to be inherently updatable and I'm seeing that I probably have to use an INSTEAD OF type clause in the view definition. Can someone show me how I would build the view to be updatable this way?
here is the create view statement:
create view CUST_VIEW
as select customer#,firstname,lastname,state
from book_customer
order by state, lastname;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您确定
order by
是您观察结果的原因吗?我可以使用 order by 子句对视图进行插入:
上述语句在 Oracle 11 R2 上运行没有问题。
您可能需要使用
USER_UPDATABLE_COLUMNS
检查可以插入哪些列:Are you sure that the
order by
is the cause for your observation?I can do an insert on a view with an order by clause:
The above statements run with no problem on Oracle 11 R2.
You might want to check with
USER_UPDATABLE_COLUMNS
which columns you can insert to:您是对的,带有 ORDER BY 子句的视图本质上不是可更新的。您所要做的就是在视图上创建一个 INSTEAD OF 触发器来执行您想要的 INSERT。
例如:假设您在表 ALL_CUST 上有一个视图 ACTIVE_CUST_VIEW
You are right that a view with ORDER BY clause is not inherently updatable. All you have to do is create an INSTEAD OF trigger on the view to execute the INSERT you want.
Eg: Lets say you have a view ACTIVE_CUST_VIEW on table ALL_CUST