今天,发现对Oracle进行更新操作时,有必要加上Commit语句,否则,会出现以下错误(准确的Oracle error id没记下来):
1. 报错:数据被lock了
2. 报错:资源耗尽
总之,因为更新数据的SQL语句块比较多(70段语句),至少要在中途加上两三个commit语句,从而防止上述两个错误。
参考文章:https://blog.csdn.net/hjxdreamer/article/details/21941487
以下内容摘自Oracle Database SQL Language Reference_11.2g.pdf
-----------------------------------------------------------------------------------------------------------------------------
COMMIT
Purpose
Use the COMMIT statement to end your current transaction and make permanent all changes performed in the transaction. A transaction is a sequence of SQL statements that Oracle Database treats as a single unit. This statement also erases all savepoints in the transaction and releases transaction locks.
Until you commit a transaction:
■ You can see any changes you have made during the transaction by querying the modified tables, but other users cannot see the changes. After you commit the transaction, the changes are visible to other users' statements that execute after the
commit.
■ You can roll back (undo) any changes made during the transaction with the ROLLBACK statement (see ROLLBACK on page 18-96).
Oracle Database issues an implicit COMMIT under the following circumstances:
■ Before any syntactically valid data definition language (DDL) statement, even if the statement results in an error
■ After any data definition language (DDL) statement that completes without an error
You can also use this statement to:
■ Commit an in-doubt distributed transaction manually
■ Terminate a read-only transaction begun by a SET TRANSACTION statement
Oracle recommends that you explicitly end every transaction in your application programs with a COMMIT or ROLLBACK statement, including the last transaction, before disconnecting from Oracle Database. If you do not explicitly commit the transaction and the program terminates abnormally, then the last uncommitted transaction is
automatically rolled back.
A normal exit from most Oracle utilities and tools causes the current transaction to be committed. A normal exit from an Oracle precompiler program does not commit the transaction and relies on Oracle Database to roll back the current transaction.
Prerequisites
You need no privileges to commit your current transaction.
To manually commit a distributed in-doubt transaction that you originally committed,
you must have FORCE TRANSACTION system privilege. To manually commit a distributed in-doubt transaction that was originally committed by another user, you must have FORCE ANY TRANSACTION system privilege.
Semantics
COMMIT
All clauses after the COMMIT keyword are optional. If you specify only COMMIT, then the
default is COMMIT WORK WRITE WAIT IMMEDIATE.
WORK
The WORK keyword is supported for compliance with standard SQL. The statements
COMMIT and COMMIT WORK are equivalent.
COMMENT Clause
This clause is supported for backward compatibility. Oracle recommends that you use named transactions instead of commit comments.
Specify a comment to be associated with the current transaction. The 'text' is a quoted literal of up to 255 bytes that Oracle Database stores in the data dictionary view DBA_2PC_PENDING along with the transaction ID if a distributed transaction becomes in doubt. This comment can help you diagnose the failure of a distributed transaction.
WRITE Clause
Use this clause to specify the priority with which the redo information generated by the commit operation is written to the redo log. This clause can improve performance by reducing latency, thus eliminating the wait for an I/O to the redo log. Use this clause to improve response time in environments with stringent response time requirements where the following conditions apply:
■ The volume of update transactions is large, requiring that the redo log be written to disk frequently.
■ The application can tolerate the loss of an asynchronously committed transaction.
The latency contributed by waiting for the redo log write to occur contributes significantly to overall response time.
You can specify the WAIT | NOWAIT and IMMEDIATE | BATCH clauses in any order.
WAIT | NOWAIT Use these clauses to specify when control returns to the user.
■ The WAIT parameter ensures that the commit will return only after the corresponding redo is persistent in the online redo log. Whether in BATCH or IMMEDIATE mode, when the client receives a successful return from this COMMIT statement, the transaction has been committed to durable media. A crash occurring after a successful write to the log can prevent the success message from returning to the client. In this case the client cannot tell whether or not the
transaction committed.
■ The NOWAIT parameter causes the commit to return to the client whether or not the write to the redo log has completed. This behavior can increase transaction throughput. With the WAIT parameter, if the commit message is received, then you can be sure that no data has been lost.
Caution: With NOWAIT, a crash occurring after the commit message is received, but before the redo log record(s) are written, can falsely indicate to a transaction that its changes are persistent.
IMMEDIATE | BATCH Use these clauses to specify when the redo is written to the log.
■ The IMMEDIATE parameter causes the log writer process (LGWR) to write the transaction's redo information to the log. This operation option forces a disk I/O, so it can reduce transaction throughput.
■ The BATCH parameter causes the redo to be buffered to the redo log, along with other concurrently executing transactions. When sufficient redo information is collected, a disk write of the redo log is initiated. This behavior is called "group commit", as redo for multiple transactions is written to the log in a single I/O operation. If you omit this clause, then the transaction commits with the IMMEDIATE behavior.
FORCE Clause
The FORCE string [, integer] clause lets you manually commit an in-doubt distributed transaction. The transaction is identified by the 'string' containing its local or global transaction ID. To find the IDs of such transactions, query the data dictionary view DBA_2PC_PENDING. You can use integer to specifically assign the transaction a system
change number (SCN). If you omit integer, then the transaction is committed using the current SCN.