要想不断循环扫描一个数据库表该怎么处理啊?具体情况是,循环扫描数据表,有合乎条件的返回,就执行下一步,没有就继续扫描

解决方案 »

  1.   

    MySQL API里哪个函数是返回记录条数的啊?我新手,不好意思啊
      

  2.   

    用存储过程实现光标遍历表。用EVENT按时间段调用这个存储过程。
      

  3.   

    差不多这样
    select count(*) from tablename where 1 into @cnt;
    set @i = 0;
    while @i < @cnt
    do
      set @str = concat('select count(*) from tablename where 1 limit ',i,',1');
      prepare s1 from @str;
      execute s1;
      drop prepare s1;
      ...
    end while;
      

  4.   

    select count(*) from tablename where 1 into @cnt;
    set @i = 0;
    while @i < @cnt
    do
      set @str = concat('select count(*) from tablename where 1 limit ',i,',1');
      prepare s1 from @str;
      execute s1;
      drop prepare s1;
      set @i = @i + 1;
      ...
    end while;