Chinaunix首页 | 论坛 | 博客
  • 博客访问: 721450
  • 博文数量: 94
  • 博客积分: 1937
  • 博客等级: 上尉
  • 技术积分: 1618
  • 用 户 组: 普通用户
  • 注册时间: 2010-11-04 18:46
个人简介

专注数据库开发管理

文章分类

全部博文(94)

文章存档

2015年(1)

2014年(2)

2013年(19)

2012年(32)

2011年(10)

2010年(30)

分类: Oracle

2012-12-20 09:45:18

ORA-12838: cannot read/modify an object after modifying it in parallel
Cause: Within the same transaction, an attempt was made to add read or modification statements on  a table after it had been modified in parallel or with direct load. This is not permitted. 
Action: Rewrite the transaction, or break it up into two transactions: one containing the initial modification and the second containing the parallel modification operation. 
在进行插入操作时加入提示/*+append*/时可减少redo log的产生并且使数据直接追加到HighWaterMark后而使性能得到一定程度的提升,但/*+append*/会对表加排它锁,从而阻止表上的除select以外所有DML语句的操作,因此应慎用,注意应及时commit,否则会产生此错误。
测试脚本:
  1. SELECT * FROM v$version;

  2. BEGIN
  3.     dbms_output.put_line('############### '||to_char(SYSDATE,'yyyy-mm-dd hh24:mi:ss')||' ###############');
  4.     
  5.     INSERT INTO t
  6.     SELECT * FROM t WHERE ROWNUM<=100;
  7.     
  8.     UPDATE t SET ID=2000 WHERE ID=10000;
  9.     
  10.     COMMIT;
  11.     
  12.     dbms_output.put_line('1--OK');
  13. EXCEPTION
  14.     WHEN OTHERS THEN
  15.         ROLLBACK;
  16.         dbms_output.put_line('-1--'||SQLERRM);
  17. END;
  18. /

  19. BEGIN
  20.     dbms_output.put_line('############### '||to_char(SYSDATE,'yyyy-mm-dd hh24:mi:ss')||' ###############');
  21.     
  22.     INSERT /*+append*/ INTO t
  23.     SELECT * FROM t WHERE ROWNUM<=100;
  24.     
  25.     UPDATE t SET ID=2000 WHERE ID=10000;
  26.     
  27.     COMMIT;
  28.     
  29.     dbms_output.put_line('1--OK');
  30. EXCEPTION
  31.     WHEN OTHERS THEN
  32.         ROLLBACK;
  33.         dbms_output.put_line('-1--'||SQLERRM);
  34. END;
  35. /

  36. BEGIN
  37.     dbms_output.put_line('############### '||to_char(SYSDATE,'yyyy-mm-dd hh24:mi:ss')||' ###############');
  38.     
  39.     INSERT /*+append*/ INTO t
  40.     SELECT * FROM t WHERE ROWNUM<=100;
  41.     
  42.     COMMIT;
  43.     
  44.     UPDATE t SET ID=2000 WHERE ID=10000;
  45.     
  46.     COMMIT;
  47.     dbms_output.put_line('2--OK');
  48. EXCEPTION
  49.     WHEN OTHERS THEN
  50.         ROLLBACK;
  51.         dbms_output.put_line('-1--'||SQLERRM);
  52. END;
  53. /

运行结果:

  1. BANNER
  2. --------------------------------------------------------------------------------

  3. Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
  4. PL/SQL Release 11.2.0.1.0 - Production
  5. CORE    11.2.0.1.0    Production
  6. TNS for 64-bit Windows: Version 11.2.0.1.0 - Production
  7. NLSRTL Version 11.2.0.1.0 - Production

  8. Executed in 0.046 seconds

  9. ############### 2012-12-19 17:45:46 ###############
  10. 1--OK


  11. PL/SQL procedure successfully completed

  12. Executed in 0 seconds

  13. ############### 2012-12-19 17:45:46 ###############
  14. -1--ORA-12838: cannot read/modify an object after modifying it in parallel


  15. PL/SQL procedure successfully completed

  16. Executed in 0 seconds

  17. ############### 2012-12-19 17:45:46 ###############
  18. 2--OK


  19. PL/SQL procedure successfully completed

  20. Executed in 0 seconds

  21. SQL>


阅读(3274) | 评论(0) | 转发(0) |
0

上一篇:oracle数组

下一篇:学习笔记——LogFile

给主人留下些什么吧!~~