我查询的sql语句如下,每个客户端都取lock_sign=N 且是排序后的第一条记录
select * from (select record_id,aa,bb from tab1  where lock_sign='N' order by cc)where rownum=1
查询之后马上执行update 
update tab1 set lock_sign='Y' where record_id=某个值(我查处来的record_id)
**********问题是************
执行第一个select到执行第二个update在网慢时需要500毫秒,在这500毫秒其间就会有另一个客户端也访问到了这条记录
阁下有何高见 不让多个客户端同时访问同一条记录?

解决方案 »

  1.   

    select * from (select record_id,aa,bb from tab1  where lock_sign='N' order by cc)where rownum=1 
    之后加上for update nowait用来锁定特定的行
      

  2.   

    select * from (select record_id,aa,bb from tab1  where lock_sign='N' order by cc)where rownum=1 
    之后加上for update nowait用来锁定特定的行
      

  3.   

    据说select永远不会阻塞
    所以其他客户端还是可以查到这条记录
    但是不能修改这条记录
      

  4.   

    呵呵,需求总会很特殊。
    如果入库的时候全部都是Lock的,然后你再把它编程UNLock呢?
      

  5.   

    学习到:for update nowait用来锁定特定的行
      

  6.   

    我不用order by 没事,我加了for update no wait之后就报错了,请问我的sql语句该怎莫写?
      

  7.   

    for update 的查询里有order by 报错,for update不让我用order by
    报告 ORA-02014错误
      

  8.   

    我把我的sql语句改成了
    select * from tbl_auto_assign where record_id=
    (select record_id from 
    (select * from tbl_auto_assign order by ADVANCE_SIGN desc,record_id) where rownum=1)
     for update
    我决的这样可以用for update来达到我的业务需求,我对for update的理解是:我锁定这一行更改提交之后其他用户才可以用同样的for update语句查询,更改不提交其他用户就一直等待。我不知道它与for update nowait的区别,有谁知道