在一堆数字中找出一个未使用的数字

发布于 2024-10-09 03:26:45 字数 251 浏览 0 评论 0原文

我有一张巨大的桌子,里面装满了数字(1001001..1009999),并且该区域肯定有一堆未使用的数字。因此,我可以通过执行以下操作来返回所有这些数字:

SELECT MY_IDENTIFIER FROM MY_TABLE

这将返回所有使用过的数字。我如何从该表中获取未使用号码的列表?我使用 JavaScript 在服务器端(rhino/jaxer)工作,我的数据库是 Oracle 10g。

谢谢,

I have a huge table filled with numbers (1001001..1009999) and there are certainly a bunch of unused numbers in that area. So, I could have all these numbers returned by doing:

SELECT MY_IDENTIFIER FROM MY_TABLE

that would return all used numbers. How could I get a list of unused numbers from that table? I work serverside (rhino/jaxer) with JavaScript and my database is Oracle 10g.

Thanks,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

恋竹姑娘 2024-10-16 03:26:45

以下查询将为您提供所需内容:

SELECT seq_num
  FROM (SELECT (lvl + &&v_from - 1) seq_num
          FROM (SELECT *
                  FROM (    SELECT LEVEL lvl
                              FROM DUAL
                        CONNECT BY LEVEL <= (&&v_to - &&v_from) + 1)))
 WHERE seq_num NOT IN (SELECT my_identifier FROM my_table);

将 &&v_to 和 &&v_from 替换为您的边界数字。

参考:http://oraqa. com/2006/01/20/如何生成两个数字之间的序列/

The following query will give you what you need:

SELECT seq_num
  FROM (SELECT (lvl + &&v_from - 1) seq_num
          FROM (SELECT *
                  FROM (    SELECT LEVEL lvl
                              FROM DUAL
                        CONNECT BY LEVEL <= (&&v_to - &&v_from) + 1)))
 WHERE seq_num NOT IN (SELECT my_identifier FROM my_table);

Replace &&v_to and &&v_from with your boundary numbers.

Reference: http://oraqa.com/2006/01/20/how-to-generate-sequence-numbers-between-two-numbers/

爱给你人给你 2024-10-16 03:26:45

Javascript 与此并没有真正的关系,不是吗?
几年前我也做过类似的事情。

我有一个表,其中包含一定范围内的所有数字,并将这两个表连接起来并选择那些无法连接的数字。负选择。

像这样的东西

 select nr bulk collect into nrs1 from tbl1 where nr not in
                (select nr from tbl2);

Javascript is not really related to that, isn't it?
I did something similiar years before.

I had a table with all numbers in a range and joined these two tables and selected those numbers which could not be joined. A negative select.

Something like

 select nr bulk collect into nrs1 from tbl1 where nr not in
                (select nr from tbl2);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文