2012-02-15 4 views
0

1〜1000の範囲のテーブルがありますが、それらは一意ですが、Oracle SQLを使用してテーブルの1〜1000の範囲内に欠落しているものを特定する必要があります、Oracle SQLの範囲は1〜1000

1,3,4,5,6,8,9,10

結果2,7

は、誰もがスクリプトにスクリプトまたはURLを助けてもらえますか。?

+2

11,12などはどうですか?彼らも欠けていないのですか? –

+0

カウントはそれほど高かったわけではありませんが、私は最高点としてmax(SheetNo)を使用できます。マイナスの場合は – icecurtain

答えて

2

あなたは使用することができます

select level from dual 
connect by level<=1000 
minus 
select mycolumn from mytable 

EDIT:

は番号がハードコードされた1000年なしシーケンスから欠落しているかを検索するには:

select level from dual 
connect by level < (select max(mycolumn) from mytable) 
minus 
select mycolumn from mytable 
+0

+1です。いいアイデア –

+0

これはちょうど私が感謝の必要なものです。 – icecurtain

0

試してみてください。

select a.check_number 
from (select level check_number from dual connect by level <= 1000) a 
where not exists 
(select null from myTable t where a.check_number = t.lookup_number) 
0
with numbers as (
    select level as i 
    from dual 
    connect by level <= (select max(some_number) from your_table) 
) 
select nr.i as missing 
from numbers nr 
    left join your_table yt on yt.some_number = nr.i 
where yt.some_number is null;