返回信息流表“ip与实际地址对应”中存储了3个字段:
start_ip,end_ip,place (起始ip,终止ip,实际地址)
现在任意给一个ip,要查出它对应的实际地址。
我是想把ip转换为整型然后通过between and来查询给定ip在哪个【start_ip,end_ip】,但又不知道如何写这样的转换函数。或者用string类型进行比较,但是ip的位数不统一。
各位大牛能否给点建议?谢谢啦^_^
这是一条镜像帖。来源:北邮人论坛 / database / #4284同步于 2010/3/22
该镜像源已超过 30 天没有更新,可能在源站已被删除。
Database机器人发帖
【求】oracle中的ip字段如何进行比较
leaflying
2010/3/22镜像同步3 回复
订阅后,新回复会通过你的通知中心匿名送达。
3 条回复
以下是将一个ip转换为标准的12位字符串的函数(不足补0),但是编译不通过。
求各种牛人排错。
create or replace function ip15 (ip char(15))
return char(15) is
Result char(15);
Temp1 varchar(3);
Indexdot integer;
begin
Result := '';
loop
Indexdot := charindex(ip,'.');
if(Indexdot = 0 or Indexdot = 1)
then exit;
elsif(Indexdot = 2)
then Temp1 := '00'||substr(ip,1,Indexdot-1);
elsif(Indexdot = 3)
then Temp1 := '0'||substr(ip,1,Indexdot-1);
elsif(Indexdot = 4)
then Temp1 := substr(ip,1,Indexdot-1);
end if;
Result := Result || Temp1;
ip := substr(ip,charindex(ip,'.')+1);
end loop;
if (length(ip) = 1)
then ip := '00'||ip;
elsif (length(ip) = 2)
then ip := '0'||ip;
end if;
Result := Result || ip;
return(Result);
end ip15;