Customise Consent Preferences

We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.

The cookies that are categorised as "Necessary" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... 

Always Active

Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.

No cookies to display.

Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.

No cookies to display.

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.

No cookies to display.

Performance cookies are used to understand and analyse the key performance indexes of the website which helps in delivering a better user experience for the visitors.

No cookies to display.

Advertisement cookies are used to provide visitors with customised advertisements based on the pages you visited previously and to analyse the effectiveness of the ad campaigns.

No cookies to display.

ORA-12838: Cannot read/modify an object after modifying it in parallel

Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
  • User AvatarKiran Dalvi
  • 10 Nov, 2021
  • 0 Comments
  • 2 Mins Read

ORA-12838: Cannot read/modify an object after modifying it in parallel

ORA-12838: Cannot read/modify an object after modifying it in parallel

Problem Statement: I am using APPEND hint with "INSERT INTO SELECT" statement, but when I am trying to SELECT the data after "INSERT INTO SELECT", it is throwing me "ORA-12838: cannot read/modify an object after modifying it in parallel"

First, check what is ORA-12838-

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.

Here is the code snippet to reproduce ORA-12838.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
ankush@thavali> desc emp
Name Null? Type
------------------------ ------- -------- -----
EMPNO NOT NULL NUMBER(4)
ENAME VARCHAR2(10)
JOB VARCHAR2(9)
MGR NUMBER(4)
HIREDATE DATE
SAL NUMBER(7,2)
COMM NUMBER(7,2)
DEPTNO NUMBER(2)
 
ankush@thavali> create table emp_new as select * from emp where 1=2;
Table created.
 
ankush@thavali> insert /*+ APPEND */ into emp_new select * from emp;
14 rows created.
 
ankush@thavali> select * from emp_new where empno = 7839;
select * from emp_new where empno = 7839
*
ERROR at line 1:
ORA-12838: cannot read/modify an object after modifying it in parallel

As per ORA-12838, Oracle cannot read/modify an object after modifying it in parallel, but we have not used the PARALLEL hint. So we should read about APPEND hint too.

The APPEND hint instructs the optimizer to use direct-path INSERT with the subquery syntax of the INSERT statement.

- Direct-path INSERT is the default in parallel mode.
- In direct-path INSERT, data is appended to the end of the table, rather than using existing space currently allocated to the table. As a result, direct-path INSERT can be considerably faster than conventional INSERT.
- If the table has referential integrity or a trigger, append hint is ignored and Oracle uses the conventional path loading

Now we completely understand "Why INSERT INTO SELECT with APPEND hint is causing ORA-12838". APPEND hint instructs the optimizer to use direct-path INSERT, which is PARALLEL by default and Oracle cannot read/modify an object after modifying it in parallel. The developer was trying to do the same, so before firing the SELECT statement on the TABLE after INSERT INTO SELECT with APPEND hint, he needs to issue a COMMIT which breaks these 2 statements into two transactions

So now let's try the previous code again, but we will issue the COMMIT before SELECT

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
ankush@thavali> drop table emp_new;
Table dropped.
 
ankush@thavali> create table emp_new as select * from emp where 1=2;
Table created.
 
ankush@thavali> insert /*+ APPEND */ into emp_new select * from emp;
14 rows created.
 
ankush@thavali> commit;
Commit complete.
 
ankush@thavalig> select * from emp_new where empno = 7839;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- ----------
7839 KING PRESIDENT 17-NOV-81 5000.15 10

Great! it worked. I hope you have Enjoyed reading this post.