我实验的时候,是把存储过程放在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;这样确实没有办法处理那种网络中断的情况的

解决方案 »

  1.   

    试试这个方法:
    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;
      

  2.   

    create procedure pro(...)
    as
    ...;
    begin
    ...;
    exception
    when NOT_LOGGED_ON then
    update table_name set filed=0 where ...;
    end;
    /
    试试以上吧,没什么好办法
      

  3.   

    你的要求应该是串行使用该表,如例
    --对表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;
    /
      

  4.   

    上面for update 为表加排他锁,其他需要加排他锁操作将被阻塞,直到commit/rollback释放
    如果用for update nowait,其他需要加排他锁操作将马上返回,并引发异常