在Oracle中,是否可以通过视图插入或更新记录? [英] In Oracle, is it possible to INSERT or UPDATE a record through a view?

查看:495
本文介绍了在Oracle中,是否可以通过视图插入或更新记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Oracle中,是否可以通过视图插入或更新记录(一行)?

In Oracle, is it possible to INSERT or UPDATE a record (a row) through a view?

推荐答案

Oracle 中的视图可以在特定条件下进行更新.这可能很棘手,并且通常是不可取的.

Views in Oracle may be updateable under specific conditions. It can be tricky, and usually is not advisable.

Oracle 10g SQL参考 :

关于可更新视图的注意事项

Notes on Updatable Views

可更新视图是可用于插入,更新或删除基表行的视图.您可以创建一个本质上可更新的视图,也可以在任何视图上创建一个INSTEAD OF触发器以使其可更新.

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.

要了解是否可以修改固有可更新视图的列以及以何种方式可以对其进行修改,请查询USER_UPDATABLE_COLUMNS数据字典视图.该视图显示的信息仅对固有的可更新视图有意义.为了使视图具有固有的可更新性,必须满足以下条件:

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:

  • 视图中的每个列都必须映射到单个表的列.例如,如果视图列映射到TABLE子句(未嵌套的集合)的输出,则该视图本质上不是可更新的.
  • 该视图不得包含以下任何构造:
    • 集合运算符
    • DISTINCT运算符
    • 聚合或分析功能
    • GROUP BY,ORDER BY,MODEL,CONNECT BY或START WITH子句
    • SELECT列表中的集合表达式
    • SELECT列表中的子查询
    • 指定为只读的子查询
    • 加入(除某些例外),如《 Oracle数据库管理员指南》中所述
    • Each column in the view must map to a column of a single table. For example, if a view column maps to the output of a TABLE clause (an unnested collection), then the view is not inherently updatable.
    • The view must not contain any of the following constructs:
      • A set operator
      • a DISTINCT operator
      • An aggregate or analytic function
      • A GROUP BY, ORDER BY, MODEL, CONNECT BY, or START WITH clause
      • A collection expression in a SELECT list
      • A subquery in a SELECT list
      • A subquery designated WITH READ ONLY
      • Joins, with some exceptions, as documented in Oracle Database Administrator's Guide

      此外,如果一个固有的可更新视图包含伪列或表达式,则不能使用引用这些伪列或表达式中任何一个的UPDATE语句更新基表行.

      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:

      • DML语句必须仅影响连接基础的一个表.
      • 对于INSERT语句,不得使用WITH CHECK OPTION创建视图,并且所有要插入值的列都必须来自保留键的表.保留键的表是基本表中每个主键或唯一键值在联接视图中也是唯一的表.
      • 对于UPDATE语句,必须从保留键的表中提取所有更新的列.如果视图是使用WITH CHECK OPTION创建的,则必须屏蔽联接列和从视图中多次引用的表中获取的列,以防止UPDATE.
      • 对于DELETE语句,如果联接产生多个保留键的表,则Oracle数据库将从FROM子句中命名的第一个表中删除,无论该视图是否使用WITH CHECK OPTION创建.

      这篇关于在Oracle中,是否可以通过视图插入或更新记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆