我实验的时候,是把存储过程放在pl/sql 中运行的在存储过程开头有加:
/*
运行前先锁定 xs 表。
*/
update SemaphoreTable set counttime=1 where tablename='xs' ;
commit;
在结束后有加:/*运行完后,解锁 */
update SemaphoreTable set counttime=0 where tablename='xs';
commit;
/*如果异常错误,解锁*/
EXCEPTION when others THEN
update SemaphoreTable set counttime=0 where tablename='xs';
commit;这样确实没有办法处理那种网络中断的情况的
/*
运行前先锁定 xs 表。
*/
update SemaphoreTable set counttime=1 where tablename='xs' ;
commit;
在结束后有加:/*运行完后,解锁 */
update SemaphoreTable set counttime=0 where tablename='xs';
commit;
/*如果异常错误,解锁*/
EXCEPTION when others THEN
update SemaphoreTable set counttime=0 where tablename='xs';
commit;这样确实没有办法处理那种网络中断的情况的
解决方案 »
- 如何在用命令创建数据库,详细一点
- 新手学oracle的问题
- ORACLE多表连接查询效率求助
- 安装oracle 出现这种问题怎么办,,急,急
- oracle 数据类型从那个表或视图读取?急急急
- 如何优化一条SQL语句???????
- 关于关系代数的除法运算的SQL实现
- oracle9安装到最后,配置oracle net configuration时报安装失败是什么原因呀,原来的oracle都删除了呀
- 大家有没有遇到过Oracle客户端工具可以使用,然而程序中无法连接的情况?
- Oracle9i如何安装?
- 错误:oracle ora-01704 (字符串过长),如何解决
- 如何在 developer 9i中使用编辑器?
declare
cursor c_lock is
select counttime from SemaphoreTable
where tablename='xs'
for update no wait
;
begin
open c_lock;
/* do something here */
close c_lock;
end;
as
...;
begin
...;
exception
when NOT_LOGGED_ON then
update table_name set filed=0 where ...;
end;
/
试试以上吧,没什么好办法
--对表test1的串行使用
create table test1(c1 int);create or replace procedure sp_t1 as
v1 int;
begin
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE; --设置事务隔离级别
select c1 into v1 from test1 where rownum = 1 for update;
--第一次对表test1的读取一定要加“for update”,其后就不用了--doYourWork;commit;
exception
when others then
rollback;
end;
/create or replace procedure sp_t2 as
v1 int;
begin
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
select c1 into v1 from test1 where rownum = 1 for update;
--doYourWork;commit;
exception
when others then
rollback;
end;
/
如果用for update nowait,其他需要加排他锁操作将马上返回,并引发异常