Is the executeBatch() performed on Oracle is done in order?

懵懂的女人 提交于 2021-02-08 08:30:30

问题


This is more of a kind of theory question to understand how the executeBatch() request is handled by Oracle.

Consider there are three insert statements (PreparedStatement) ,say statement 1, statement2 and statement 3 are added to execute as a batch using executeBatch() method and over Oracle. Will there be a chance that the execution of statement 2 to complete even before statement 1 completes? In other words, can the insert operation by statement 2 succeed before the insert performed by operation ?

Provided Autocommit is set to false.

Thanks in Advance.


回答1:


Provided auto-commit set to false

Then the answer is straight-forward if you are concerning on querying in the middle of insert (as you have mentioned in comment on another answer):

Given that in same connection, you cannot do query before your previous insert statement finished, that means your query needs to be from another connection.

In Oracle, before any insert/update/delete is committed, the change is not visible to other connection. That means, the query will see the snapshot before any insert is done, until you commit the change.

Then you should have no concern about the insert order in such aspect.




回答2:


The database will execute your statements in the order you put them into the batch.

There is no out-of-order or concurrent execution.




回答3:


When a batch is processed, operations are performed in the order in which they were batched.

Oracle Database JDBC Developer's Guide



来源:https://stackoverflow.com/questions/27032778/is-the-executebatch-performed-on-oracle-is-done-in-order

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!