更新指向 Oracle 视图的结果集

Updating Resultset that points to an Oracle view

是否可以通过 Resultset 更新 Oracle 视图?询问我的代码在执行 rs.updateRow() 调用时给我的权限不足错误。我已经检查过,我肯定可以访问 table/view.

代码如下:

white (rs.next()) {
  int updateStatus = getPSCforAction(status);
  rs.updateInt("SPSC", updateStatus);
  rs.updateRow;
}

SELECT 语句的变化取决于操作,但它总是查询一个 Oracle 视图(在某些情况下是多个视图)。我的主要问题是是否可以通过 resultSet 更新 Oracle 视图(或多个视图)?

要回答您的问题,必须查看您的视图定义和用于在您的 Java 代码中生成结果集的 SELECT 语句。不看这个很难给出答案

无论如何,Oracle Database JDBC Developer's guide:

中描述了一般规则和限制

Result Set Limitations

The following limitations are placed on queries for enhanced result sets. Failure to follow these guidelines results in the JDBC driver choosing an alternative result set type or concurrency type.

To produce an updatable result set:

  • A query can select from only a single table and cannot contain any join operations.

  • In addition, for inserts to be feasible, the query must select all non-nullable columns and all columns that do not have a default value.

  • A query cannot use SELECT * . However, there is a workaround for this.

  • A query must select table columns only.

  • It cannot select derived columns or aggregates, such as the SUM or MAX of a set of columns.

To produce a scroll-sensitive result set:

  • A query cannot use SELECT *. However, there is a workaround for this.

  • A query can select from only a single table.

Scrollable and updatable result sets cannot have any column as Stream. When the server has to fetch a Stream column, it reduces the fetch size to one and blocks all columns following the Stream column until the Stream column is read. As a result, columns cannot be fetched in bulk and scrolled through.


他们含糊地写道:

  • A query can select from only a single table and cannot contain any join operations.

可能是指"exlusively from tables, but not views",但也可能是指:"from tables and views",没人知道,必须测试一下。


另一个可能的问题 - 您的视图可能无法更新,即它不符合 the following rules:

Notes on Updatable Views The following notes apply to 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:

  • 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

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:

  • The DML statement must affect only one table underlying the join.

  • For an INSERT statement, the view must not be created WITH CHECK OPTION, and all columns into which values are inserted must come from a key-preserved table. A key-preserved table is one for which every primary key or unique key value in the base table is also unique in the join view.

  • For an UPDATE statement, the view must not be created WITH CHECK OPTION, and all columns updated must be extracted from a key-preserved table.

  • For a DELETE statement, if the join results in more than one key-preserved table, then Oracle Database deletes from the first table named in the FROM clause, whether or not the view was created WITH CHECK OPTION.