focus on linux, c/c++, lua

记录一个存储过程

BEGIN
   
set @lastpid = 0;
   
set @count = 0;
   
set @num = 0;
   
update tb_recyle set r_lockip = null where r_lockip is not null and r_locktime <= (UNIX_TIMESTAMP() - 60);        #5分钟之前的 自动解锁
    
if (select count(*from tb_recyle where r_lockip is null< 20 then
       
select @lastpid := l_lastpid from tb_lastpid limit 1;
       
begin
        flag: loop
          
if not exists (select * from tb_reverseid where r_pid = @lastpid+@numthen
             
insert into tb_recyle(r_pid, r_lockip, r_locktime) values (@lastpid+@numNULL0);
             
set @count = @count + 1;
             
set @num = @num + 1;
             
if @count >= 20 then
                
update tb_lastpid set l_lastpid = @lastpid+@num where l_lastpid = @lastpid;
                leave flag;
            
end if;
          
else
            
set @num = @num + 1;
          
end if;
        
end loop flag;
      
end;
   
end if;
   
select * from tb_recyle where r_lockip is null  limit 20;
END

注意这个存储里有对空字符进行了操作,在表设计的时候要注意该字符,要被设置成允许为空才行。

posted on 2011-08-15 11:50 zuhd 阅读(360) 评论(0)  编辑 收藏 引用 所属分类: my tips


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理