码迷,mamicode.com
首页 > 数据库 > 详细

IP地址字符转INT(PLSQL版)

时间:2015-04-17 18:23:47      阅读:166      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!