var Max,Num,i:integer; begin Max:=0; Num:=0; for i:=0 to 10000 do begin if sql语句查这个号码是否存在=false then num=num+1 ; else num:=0; //不连续清0 if num>max then max:=num; end;edn;
我用的是Oracle数据库测试。 测试的Tian_A表有一个字段A number(5)类型. 里面可以存放你使用过的数字。 select Max(a.a-b.a) from (select rownum as RN,a from (select a from tian_a order by a)) A,(select rownum as RN,a from (select a from tian_a order by a)) B where (a.RN=b.RN+1) or (a.RN=1 and B.RN is null);但本算法有一个缺陷,就是如果1这个数字没使用就可能会有问题。所以 建议你不管用没用都在记录里插入一个0。
hawksoft(明月清风) 的算法很好,or (a.RN=1 and B.RN is null); 好像没必要
根据数据中记录构造一个长度为10000的字符,如1已使用,则str[0] = 1,否则为默认的0采用对折的算法查找这个字符串是最长的连续0,用strpos函数,
要用一个SQL语句的话还是比较困难。
Max,Num,i:integer;
begin
Max:=0;
Num:=0;
for i:=0 to 10000 do
begin
if sql语句查这个号码是否存在=false then
num=num+1 ;
else
num:=0; //不连续清0
if num>max then
max:=num;
end;edn;
测试的Tian_A表有一个字段A number(5)类型.
里面可以存放你使用过的数字。
select Max(a.a-b.a) from (select rownum as RN,a from (select a from tian_a order by a)) A,(select rownum as RN,a from (select a from tian_a order by a)) B
where (a.RN=b.RN+1) or (a.RN=1 and B.RN is null);但本算法有一个缺陷,就是如果1这个数字没使用就可能会有问题。所以
建议你不管用没用都在记录里插入一个0。