commit work php,COMMIT WORK RELEASE和COMMIT TRANSACTION有什么区别?

Using the RELEASE Option

Oracle9i rolls back changes automatically if your program terminates abnormally. Abnormal termination occurs when your program does not explicitly commit or roll back work and disconnect using the RELEASE ××ded SQL statement.

Normal termination occurs when your program runs its course, closes open cursors, explicitly commits or rolls back work, disconnects, and returns control to the user. Your program will exit gracefully if the last SQL statement it executes is either

EXEC SQL COMMIT WORK RELEASE END-EXEC.

or

EXEC SQL ROLLBACK WORK RELEASE END-EXEC.

where the token WORK is optional. Otherwise, locks and cursors acquired by your user session are held after program termination until Oracle9i recognizes that the user session is no longer active. This might cause other users in a multiuser environment to wait longer than necessary for the locked resources.

Using the SET TRANSACTION Statement

You can use the SET TRANSACTION statement to begin a read-only or read/write transaction, or to assign your current transaction to a specified rollback segment. A COMMIT, ROLLBACK, or data definition statement ends a read-only transaction.

Because they allow "repeatable reads," read-only transactions are useful for running multiple queries against one or more tables while other users update the same tables. During a read-only transaction, all queries refer to the same snapshot of the database, providing a multitable, multiquery, read-consistent view. Other users can continue to query or update data as usual. An example of the SET TRANSACTION statement follows:

EXEC SQL SET TRANSACTION READ ONLY END-EXEC.

The SET TRANSACTION statement must be the first SQL statement in a read-only transaction and can appear only once in a transaction. The READ ONLY parameter is required. Its use does not affect other transactions. Only the SELECT (without FOR UPDATE), LOCK TABLE, SET ROLE, ALTER SESSION, ALTER SYSTEM, COMMIT, and ROLLBACK statements are allowed in a read-only transaction.

In the following example, a store manager checks sales activity for the day, the past week, and the past month by using a read-only transaction to generate a summary report. The report is unaffected by other users updating the database during the transaction.

EXEC SQL SET TRANSACTION READ ONLY END-EXEC.

EXEC SQL SELECT SUM(SALEAMT) INTO

266faa3e2451dd0bb0047cc3ca69ae30.gifAILY FROM SALES

WHERE SALEDATE = SYSDATE END-EXEC.

EXEC SQL SELECT SUM(SALEAMT) INTO :WEEKLY FROM SALES

WHERE SALEDATE > SYSDATE - 7 END-EXEC.

EXEC SQL SELECT SUM(SALEAMT) INTO :MONTHLY FROM SALES

WHERE SALEDATE > SYSDATE - 30 END-EXEC.

EXEC SQL COMMIT WORK END-EXEC.

* --  simply ends the transaction since there are no changes

* --  to make permanent

* --  format and print report

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值