日期:2014-05-17  浏览次数:21055 次

oracle视图增删改的问题
一个视图,sql语句如下
CREATE OR REPLACE myview AS
select ... from tb1
union all
select ... from tb2

现在我要对myview这个视图进行update操作
update
        myview v 
    set
        v.data1 = 2 
    where
        v.id = '123'

然后报错了,<SQL Error: 1732, SQLState: 42000><ORA-01732: 此视图的数据操纵操作非法>

请问各位大牛,这是为什么,网上查不到资料啊


------解决方案--------------------
引用:
一个视图,sql语句如下
CREATE OR REPLACE myview AS
select ... from tb1
union all
select ... from tb2

现在我要对myview这个视图进行update操作
update
        myview v 
    set
        v.data1 = 2 
    where
        v.id = '123'

然后报错了,<SQL Error: 1732, SQLState: 42000><ORA-01732: 此视图的数据操纵操作非法>

请问各位大牛,这是为什么,网上查不到资料啊

这个文档更清楚

http://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_8004.htm#SQLRF01504
------解决方案--------------------
引用:
一个视图,sql语句如下
CREATE OR REPLACE myview AS
select ... from tb1
union all
select ... from tb2

现在我要对myview这个视图进行update操作
update
        myview v 
    set
        v.data1 = 2 
    where
        v.id = '123'

然后报错了,<SQL Error: 1732, SQLState: 42000><ORA-01732: 此视图的数据操纵操作非法>

请问各位大牛,这是为什么,网上查不到资料啊


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: