首页 > 数据库技术 > 详细

IP地址字符转INT(PLSQL版)

时间:2015-04-17 18:20:58      阅读:444      评论:0      收藏:0      [点我收藏+]


declare
val varchar2(1024);
val_new varchar2(1024);
i integer;
p1 integer;
p2 integer;
p3 integer;
p4 integer;
ip integer;
begin
    val := ‘192.168.010.017‘;
    
    p1 := 0;
    p2 := 0;
    p3 := 0;
    p4 := 0;
   
    i := instr(val,‘.‘,1);
    if i <> 0 then
      val_new := substr(val,1,i-1);
      p1 := to_number(val_new);
      dbms_output.put_line(to_char(p1));
      val := substr(val,i+1);    
      i := instr(val,‘.‘,1);
      if i <> 0 then
          val_new := substr(val,1,i-1);
          p2 := to_number(val_new);
          dbms_output.put_line(to_char(p2));         
          val := substr(val,i+1);
          i := instr(val,‘.‘,1);
          if i <> 0 then
            val_new := substr(val,1,i-1);
            p3 := to_number(val_new);
            dbms_output.put_line(to_char(p3));
            val := substr(val,i+1);
            p4 := to_number(val);
            dbms_output.put_line(to_char(p4));
          end if;
      end if;
    end if;
    

    ip := p4 + p3*(power(2,8)) + p2*(power(2,16)) + p1*(power(2,24));
    dbms_output.put_line(to_char(ip));
   
    exception
      when others then
        null;

end;



IP地址字符转INT(PLSQL版)

原文:http://blog.csdn.net/cackeme/article/details/45098247

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!