adodataset1.Close;
  adodataset1.CommandText:='select * from tb_emp_task where busi='''+s+''' '+
  ' and  is null and emp_id is null and rownum='+inttostr(1);
  adodataset1.Open;
  if not adodataset1.IsEmpty then
    begin
      try
        u_dm.DataModule1.ADOConnection1.BeginTrans;
        adoquery1.Close;
        adoquery1.SQL.Clear;
        str_sql:='update tb_emp_task set emp_id='''+u_logon.str_emp_id+''' where '+
        ' busi='''+s+''' and  is null and phone='''+adodataset1['phone']+''' ';
        adoquery1.SQL.Add(str_sql);
        adoquery1.ExecSQL;
        u_dm.DataModule1.ADOConnection1.CommitTrans;
      except
        u_dm.DataModule1.ADOConnection1.RollbackTrans;
        application.MessageBox('ADOQUERY控件更新出错!更新失败!','警告')
      end;
    end
    else
    begin
     application.MessageBox('没有资料了','提示');
     exit;
    end;
我在程序中使用ORACLE事务提取资料,怎么每天老是存在两三个数据被两个人都获得,我认为这样应该可以呀,当一个人提一条记录时,ORACLE事务应该把这条记录锁定啊,怎么还会被另外的人得到,大家有没有好的解决方法,在线等待,有好方法马上给分,谢谢........

解决方案 »

  1.   

    这样试试:
      adodataset1.Close;
      adodataset1.CommandText:='select * from tb_emp_task where busi='''+s+''' '+
      ' and  is null and emp_id is null and rownum='+inttostr(1) + ' for update';
      u_dm.DataModule1.ADOConnection1.BeginTrans;
      try
        adodataset1.Open;
        if not adodataset1.IsEmpty then
        ...
      

  2.   

    你看一下设置一下ADOConnection1.IsolationLevel的级别可以不?希望能够对你有用
      

  3.   

    也就是在select 语句中加上for update ,这样是不是就锁定了这一条记录,那为什么要用for update ,如果我在事务中用到delete 语句,那是不是还是用for update 啊,能不能说一下原理呢,多谢
      

  4.   

    我试过了, plainsong(短歌) 的方法不行,如果加上‘for update’的话,一个资料都提不出来了。
    luckzhangs(飞)  这位兄弟能不能给出确定的答复,再说ADOConnection1.IsolationLevel 的级别那么多,到底用哪一个呀,大家不要吝啬自己的方法,给俺说一下吧,我会马上给分的,谢谢.....