Oracle SQL:有没有办法列出IP版本为IPv6的所有条目?

问题描述 投票:-3回答:2

在表中,我们有多行记录登录的IP地址。这些天我们也从IPv6地址获取登录。

我试图找到一种方法来列出我们有IPv6条目的所有行。

任何建议都非常感谢。

谢谢。

sql oracle ipv6
2个回答
2
投票

据推测,你可以这样做:

select t.*
from t
where not regexp_like(ip, '[0-9]{1-3}.[0-9]{1-3}.[0-9]{1-3}.[0-9]{1-3}')

或者更简单:

select t.*
from t
where ip like '%:%'  -- ipv6 contains colons

0
投票

因为IPv6地址的大小为128位,每个冒号后有4位数,我们可以这样:

create table ns_tab3 (val varchar(100));
insert into ns_tab3 values('2002:2002:2002:2002:2002:2002:2002:2002'); 
insert into ns_tab3 values('2002:2432:2432:2543:2974:2002:2002:2002'); 
insert into ns_tab3 values('2002:2002:2002:2002:2002:2002:2002:2432'); 
insert into ns_tab3 values('2002:2002:2002:2002:2002:2002:2002:1920'); 
insert into ns_tab3 values('2002:2002:2002:2002:2002:2002:2002:0201'); 
select * from ns_tab3;

select * from ns_tab3 where regexp_like(val,'[0-9]{4}:[0-9]{4}:[0-9]{4}:[0-9]{4}:[0- 
9]{4}:[0-9]{4}:[0-9]{4}:[0-9]{4}');
© www.soinside.com 2019 - 2024. All rights reserved.