如何从一系列数字中检查任何遗漏的数字? [英] How to check any missing number from a series of numbers?

查看:79
本文介绍了如何从一系列数字中检查任何遗漏的数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个创建大学录取系统的项目;这些技术是Java和Oracle.

I am doing a project creating an admission system for a college; the technologies are Java and Oracle.

在其中一个表中,存储了预先生成的序列号.之后,将根据这些序列号输入申请人的表格数据.我的要求是,完成输入流程后,我将必须生成一份Lot明智的报告.如果在喂入预先生成的序列号期间,任何序列号都丢失了.

In one of the tables, pre-generated serial numbers are stored. Later, against those serial numbers, the applicant's form data will be entered. My requirement is that when the entry process is completed I will have to generate a Lot wise report. If during feeding pre-generated serial numbers any sequence numbers went missing.

例如,在一个表中,序列号是7001、7002、7004、7005、7006、7010. 从以上系列中可以清楚地看出,从7001到7010缺少的数字是7003、7007、7008和7009

For example, say in a table, the sequence numbers are 7001, 7002, 7004, 7005, 7006, 7010. From the above series it is clear that from 7001 to 7010 the numbers missing are 7003, 7007, 7008 and 7009

Oracle中是否有可用的DBMS功能来找出这些数字,或者是否有任何存储过程可以满足我的目的,那么请提出一种算法.

Is there any DBMS function available in Oracle to find out these numbers or if any stored procedure may fulfill my purpose then please suggest an algorithm.

我可以找到Java中的一些技术,但是为了提高速度,我想在Oracle中找到解决方案.

I can find some techniques in Java but for speed I want to find the solution in Oracle.

推荐答案

无需对9进行硬编码的解决方案:

A solution without hardcoding the 9:

select min_a - 1 + level
     from ( select min(a) min_a
                 , max(a) max_a
              from test1
          )
  connect by level <= max_a - min_a + 1
    minus
   select a
     from test1


结果:


Results:

MIN_A-1+LEVEL
-------------
         7003
         7007
         7008
         7009

4 rows selected.

这篇关于如何从一系列数字中检查任何遗漏的数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆