Explicit (Manual) Data Locking (364)

Oracle always performs locking automatically to ensure data concurrency, data
integrity, and statement-level read consistency. However, you can override the Oracle
default locking mechanisms. Overriding the default locking is useful in situations such
as these:
■ Applications require transaction-level read consistency or repeatable reads. In
other words, queries in them must produce consistent data for the duration of the
transaction, not reflecting changes by other transactions. You can achieve
transaction-level read consistency by using explicit locking, read-only transactions,
serializable transactions, or by overriding default locking.
■ Applications require that a transaction have exclusive access to a resource so that
the transaction does not have to wait for other transactions to complete.

Oracle’s automatic locking can be overridden at the transaction level or the session
level.

At the transaction level, transactions that include the following SQL statements
override Oracle’s default locking:
■ The SET TRANSACTION ISOLATION LEVEL statement
■ The LOCK TABLE statement (which locks either a table or, when used with views,
the underlying base tables)
■ The SELECT ... FOR UPDATE statement
Locks acquired by these statements are released after the transaction commits or rolls
back.
At the session level, a session can set the required transaction isolation level with the
ALTER SESSION statement.

Note: If Oracle’s default locking is overridden at any level, the
database administrator or application developer should ensure that
the overriding locking procedures operate correctly. The locking
procedures must satisfy the following criteria: data integrity is
guaranteed, data concurrency is acceptable, and deadlocks are not
possible or are appropriately handled.

显示(手工)加锁
在以下情况下手工加锁(覆盖Oracle默认的锁机制)非常有用
1. 应用需要事务级别的一致性读或者可重复读. 用户可以显示地对数据加锁,使用只读事务
或串行化事务,或覆盖默认的锁,从而实现事务级的读一致性
2. 应用要求事务必须以排他地访问某种资源,而不需要等待其他事务完成
3. 用户可以在事务级或会话级覆盖 Oracle 默认采用的锁
4. 在事务级别 , 可以使用下面的语句来覆盖Oracle默认的锁 ... , 这些锁在事务提交或回滚后
释放
5. 在会话级别,可以使用alter session 设置事务隔离级别
6. 手工加锁操作必须满足以下标准:保证数据完整性,提供足够的数据并发能力,
不会发生死锁或能够正确处理死锁

[@more@]

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10599713/viewspace-992629/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/10599713/viewspace-992629/

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值