要生成一組所有IPv4的人可以使用一個交叉連接和CTE與16條記錄和交叉連接。但是我還不確定你真的是什麼。
with cte (A) as (
SELECT 0 from dual UNION ALL
SELECT 1 from dual UNION ALL
SELECT 2 from dual UNION ALL
SELECT 3 from dual UNION ALL
SELECT 4 from dual UNION ALL
SELECT 5 from dual UNION ALL
SELECT 6 from dual UNION ALL
SELECT 7 from dual UNION ALL
SELECT 8 from dual UNION ALL
SELECT 9 from dual UNION ALL
SELECT 10 from dual UNION ALL
SELECT 11 from dual UNION ALL
SELECT 12 from dual UNION ALL
SELECT 13 from dual UNION ALL
SELECT 14 from dual UNION ALL
SELECT 15 from dual),
--Get data set for 0 to 255 numbers.
Get256Range as (SELECT row_number() over (order by A.A)-1 seg
FROM CTE A
CROSS JOIN cte B)
--Now cross join the 256 4 times for each class of Ip.
SELECT A.Seg ||'.'|| B.Seg||'.'|| C.Seg||'.'||D.Seg as IPAddress
from Get256Range A
CROSS JOIN Get256Range B
CROSS JOIN Get256Range C
CROSS JOIN Get256Range D
--Not sure what part of the "set" you need but one could change these values
--Limited for sizing; but one could create a table of all IPv4 addresses...
WHERE A.seg = 12
and B.seg = 123;
您可以根據需要包括前導零...
lpad(A.Seg,3,'0') ||'.'|| lpad(B.Seg,3,'0')||'.'|| lpad(C.Seg,3,'0')||'.'|| lpad(D.Seg,3,'0') IpAddressWithLeadZero
這讓人們可以進行排序或基於特定範圍過濾器
所以只能返回這些較大(不是最有效的)
WHERE lpad(A.Seg,3,'0') ||'.'|| lpad(B.Seg,3,'0')||'.'|| lpad(C.Seg,3,'0')||'.'|| lpad(D.Seg,3,'0') >='012.123.060.165'
可能更爲有效:
WHERE (A.Seg = 12 and B.Seg = 123 and C.Seg = 60 and D.Seg > 165) OR (A.Seg = 12 and B.Seg = 123 and C.Seg > 60) OR (A.Seg = 12 and B.Seg > 123) OR (A.Seg > 12)
你怎麼從這些默認值我有可能產生IP地址是什麼意思?您是否只需要IP地址> 12.123.60.256的完整IP4地址範圍?不知道你在做什麼。 – xQbert
我的意思是我有IP號碼的默認值。它是12.123.60.165。然後我必須生成新的IP號碼,分別是12.123.60.167,12.123.60.168,12.123.60.169等等。直到以(256)12.123.60.256結尾。直到IP數量的最大IP數將是256.256.256.256。 –
生成4,213,638,225條記錄......這就是40億2.13億美元需要一些時間。但是有256個記錄的表的4個交叉連接似乎工作;而你的起始IP只會消除約14,612,400條記錄;或0.3456%不要指望它很快......但你可以用這些#表創建一個表,我想...... – xQbert