在一个存储过程里面,首先获得一个唯一的seqid ,然后进行一系列的操作插入到一个表中,表里面有个seqid字段,主要是用于并发操作,
 最后在 存储过程里面执行:
  select * from xxx where seqid=;
  delete from xxx where seqid=;
不知道怎么的,有时候 删除不了数据。但是单个测试就不会存在那情况,都可以删除掉,

解决方案 »

  1.   

    并发的时候,注意采用事务(使用支持事务的引擎哦),用begin 和commit把它们括起来,应该能确保一致。
      

  2.   

    你是如何取得 seqid 的?
      

  3.   

    我是写了2个函数:
    fn_nextval
    UPDATE sequence  
      SET          current_value = current_value + increment  
      WHERE NAME = seq_name;  
     RETURN fn_currval(seq_name);  
        END
    fn_currval
    BEGIN
     DECLARE curVal INTEGER;  
     SET curVal = 0;  
     SELECT current_value INTO curVal FROM sequence WHERE NAME = seq_name;  
     RETURN curVal;  
    END
      

  4.   

    我是写了2个函数:
    fn_nextval
    UPDATE sequence  
      SET          current_value = current_value + increment  
      WHERE NAME = seq_name;  
     RETURN fn_currval(seq_name);  
        END
    fn_currval
    BEGIN
     DECLARE curVal INTEGER;  
     SET curVal = 0;  
     SELECT current_value INTO curVal FROM sequence WHERE NAME = seq_name;  
     RETURN curVal;  
    END
      

  5.   

    我是写了2个函数:
    fn_nextval
    UPDATE sequence  
      SET          current_value = current_value + increment  
      WHERE NAME = seq_name;  
     RETURN fn_currval(seq_name);  
        END
    fn_currval
    BEGIN
     DECLARE curVal INTEGER;  
     SET curVal = 0;  
     SELECT current_value INTO curVal FROM sequence WHERE NAME = seq_name;  
     RETURN curVal;  
    END
      

  6.   

    ACMAIN_CHM 你那有什么好的方法取那个seqid吗,
     在存储过程最后写:
      select * from xxx where seqid=1111;
     delete from xxx where seqid=1111;
    这个有什么影响吗?
      

  7.   


    从你的2个SQL命令,看不出来任何错误。只要seqid 符合记录的,肯定都会删除掉。
    你是怎么样测试到有的可以有的不行的??
      

  8.   

    现在是按下面方式做的,就是有时候删除不了;
    delete from xxxx where SeqId=seqNum;
    declare tmsid varchar(50) ;
    DECLARE depthid int ;
    DECLARE seqNum int ;
    set depthid=0;
    set seqNum=global_equity.fn_nextval('TREE');
    insert into xxxx(
       SeqId, 
       MSId, 
    MSName, 
    ShortName, 
    ParentId, 
    IndustryType, 
    TableType, 
    IsHide, 
    LevelId
    )
    select 
       seqNum,
       MSId, 
    MSName, 
    ShortName, 
    ParentId, 
    IndustryType, 
    TableType, 
    IsHide, 
    depthid 
    from yyy where ParentId=i_msId and IndustryType=i_industryType ;WHILE ROW_COUNT()>0 DO
    set depthid=depthid+1;
    insert into xxxx(
       SeqId, 
       MSId, 
    MSName, 
    ShortName, 
    ParentId, 
    IndustryType, 
    TableType, 
    IsHide, 
    LevelId
    )
    select 
       seqNum,
       a.MSId, 
    a.MSName, 
    a.ShortName, 
    a.ParentId, 
    a.IndustryType, 
    a.TableType, 
    a.IsHide, 
    depthid 
     from yyy a,xxxx b 
    where a.ParentId=b.MSId 
       and b.LevelId=depthid-1 
    and a.IndustryType=i_industryType;
    END WHILE;select * from xxxx where SeqId=seqNum;
    delete from xxxx where SeqId=seqNum;
      

  9.   

    本来  xxxx  是想用 临时表的,但是临时表不能那样操作报错
      

  10.   

    临时表的话,会报 can not reopen table: