[20160311]ora-01732.txt

[20160311]ora-01732.txt

--今天工作出现ora-01732错误,做一个测试例子,做一个记录:

1.环境:

SCOTT@test01p> @ ver1

PORT_STRING          VERSION     BANNER                                                                        CON_ID
-------------------- ----------- ----------------------------------------------------------------------------- ------
IBMPC/WIN_NT64-9.1.0 12.1.0.1.0  Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production       0

SCOTT@test01p> create table dept2 as select * from dept ;
Table created.

2.测试:
SCOTT@test01p> delete from (select * from dept2 where rownum=1);
delete from (select * from dept2 where rownum=1)
            *
ERROR at line 1:
ORA-01732: data manipulation operation not legal on this view

D:\tools\rlwrap>oerr ora 1732
oerr ora 1732
01732, 00000, "data manipulation operation not legal on this view"
// *Cause:
// *Action:

--我操作的对象是表,不是视图啊,为什么呢?

3.但是如果你查询如下:
SCOTT@test01p> select *  from (select * from dept2 where rownum=1);
    DEPTNO DNAME          LOC
---------- -------------- -------------
        10 ACCOUNTING     NEW YORK

SCOTT@test01p> @ dpc '' ''
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID  d8c0y9masj9g5, child number 0
-------------------------------------
select *  from (select * from dept2 where rownum=1)
Plan hash value: 1094723229
------------------------------------------------------------------------------
| Id  | Operation           | Name  | E-Rows |E-Bytes| Cost (%CPU)| E-Time   |
------------------------------------------------------------------------------
|   0 | SELECT STATEMENT    |       |        |       |     2 (100)|          |
|   1 |  VIEW               |       |      1 |    30 |     2   (0)| 00:00:01 |
|*  2 |   COUNT STOPKEY     |       |        |       |            |          |
|   3 |    TABLE ACCESS FULL| DEPT2 |      1 |    20 |     2   (0)| 00:00:01 |
------------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
   1 - SEL$2 / from$_subquery$_001@SEL$1
   2 - SEL$2
   3 - SEL$2 / DEPT2@SEL$2
Predicate Information (identified by operation id):
---------------------------------------------------
   2 - filter(ROWNUM=1)

--可以注意ID=1,已经转换为视图.如果这样写:

SCOTT@test01p> select *  from (select * from dept2 ) where rownum=1;
    DEPTNO DNAME          LOC
---------- -------------- -------------
        10 ACCOUNTING     NEW YORK

SCOTT@test01p> @ dpc '' ''
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID  4zkrhx0q6g68j, child number 0
-------------------------------------
select *  from (select * from dept2 ) where rownum=1
Plan hash value: 2935958459
-----------------------------------------------------------------------------
| Id  | Operation          | Name  | E-Rows |E-Bytes| Cost (%CPU)| E-Time   |
-----------------------------------------------------------------------------
|   0 | SELECT STATEMENT   |       |        |       |     2 (100)|          |
|*  1 |  COUNT STOPKEY     |       |        |       |            |          |
|   2 |   TABLE ACCESS FULL| DEPT2 |      1 |    20 |     2   (0)| 00:00:01 |
-----------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
   1 - SEL$F5BB74E1
   2 - SEL$F5BB74E1 / DEPT2@SEL$2
Predicate Information (identified by operation id):
---------------------------------------------------
   1 - filter(ROWNUM=1)

--知道这些就明白什么回事了.写成如下:

SCOTT@test01p> update (select * from dept2 ) set dname='cccc' where rownum=1;
1 row updated.

SCOTT@test01p> select * from dept2;
    DEPTNO DNAME          LOC
---------- -------------- -------------
        10 cccc           NEW YORK
        20 RESEARCH       DALLAS
        30 SALES          CHICAGO
        40 OPERATIONS     DALLAS

SCOTT@test01p> rollback ;
Rollback complete.

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/267265/viewspace-2055891/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/267265/viewspace-2055891/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值