ALTER SESSION ENABLE PARALLEL DML;
INSERT /*+ ENABLE_PARALLEL_DML */
…
1. Create a new table.
SQL> create table test_dmls as select * from objects_objects;
Table TEST_DMLS created.
2. Alter the session and enable parallel DML.
SQL> alter session enable parallel dml;
Session altered.
3. Insert into the table with PARALLEL hint.
SQL> insert /*+ parallel(test_dmls 4) */ into test_dmls
select /*+ parallel(test_dmls 4) */ * from test_dmls;
76,237 rows inserted.
4. Select from the table without performing a commit or rollback. You will get and error.
SQL> select count(*) from test_dmls;
Error starting at line : 1 in command -
select count(*) from test_dmls
SQL ORA-12838: cannot read/modify an object after modifying it in parallel
More Details :
https://docs.oracle.com/error-help/db/ora-12838/
SQL> !oerr ora 12838
12838, 00000, "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.
5. Perform a commit.
SQL> commit;
Commit complete.
6. After the commit is done, now you can select again from the table.
SQL> select count(*) from test_dmls;
COUNT(*)
___________
152474
7. Perform a parallel insert using ENABLE_PARALLEL_DML hint.
SQL> insert /*+ enable_parallel_dml(test_dmls 4) */ into test_dmls
select /*+ enable_parallel_dml(test_dmls 4) */ * from test_dmls;
152,474 rows inserted.
8. Select from the table without performing a commit or rollback. Now you will NOT get an error.
SQL> select count(*) from test_dmls;
COUNT(*)
___________
304948
9. Perform another parallel insert without a commit or rollback. No error.
SQL> insert /*+ enable_parallel_dml(test_dmls 4) */ into test_dmls
2* select /*+ enable_parallel_dml(test_dmls 4) */ * from test_dmls;
304,948 rows inserted.
SQL> /
609,896 rows inserted.
SQL> /
1,219,792 rows inserted.
SQL> select count(*) from test_dmls;
COUNT(*)
___________
2439584