IP地址转化为数字,charindex ,SUBSTRING
SET NOCOUNT ON;
declare @I_PCity table
(
IPStart nvarchar(),
Area nvarchar(),
CityID int,
IPID int )
declare @IPStart nvarchar(),
@diana int, --存放点
@dianb int,
@dianc int, @liea bigint, -- 存放列
@lieb bigint,
@liec bigint,
@lied bigint, @intlon bigint --存放化为的整数
insert into @I_PCity(IPStart, Area, CityID, IPID ) select IPStart, Area, CityID, IPID from I_IPCity (nolock) where IPID>= and IPStart is not null and IP3 is null
--
while( exists(select top * from @I_PCity))
begin set @IPStart= (select top IPStart from @I_PCity );
set @diana= charindex('.',@IPStart) --第一个点的下标
set @dianb= charindex('.',@IPStart, @diana + ) --第二个点的下标
set @dianc= charindex('.',@IPStart, @dianb + ) --第三个点的下标 set @liea = SUBSTRING(@IPStart,,@diana-) --第一列的值
set @lieb =SUBSTRING(@IPStart,@diana+,@dianb-@diana- )--第二列的值
set @liec =SUBSTRING(@IPStart,@dianb+,@dianc-@dianb- )--第三列的值
set @lied =SUBSTRING(@IPStart,@dianc+, LEN(@IPStart))--第四列的值
set @intlon= @lied+(@liec*)+(@lieb*)+(@liea*) --拼为整数
update I_IPCity set IP3 =@intlon where IPID= (select top IPID from @I_PCity)
delete top() from @I_PCity
end
返回前台所查到的结果:
USE [91hurong]
GO
/****** Object: StoredProcedure [dbo].[ProIP] Script Date: 08/13/2015 08:40:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[ProIP]
-- Add the parameters for the stored procedure here
@str varchar()
AS
BEGIN declare @IPStart nvarchar(), --存放传入的数据
@diana int, --存放点
@dianb int,
@dianc int, @liea bigint, -- 存放列
@lieb bigint,
@liec bigint,
@lied bigint, @intlon bigint --存放化为的整数
set @IPStart= @str; --传入的IP'1.11.6.6'
-- set @IPStart= '1.11.6.6';
set @diana= charindex('.',@IPStart) --第一个点的下标
set @dianb= charindex('.',@IPStart, @diana + ) --第二个点的下标
set @dianc= charindex('.',@IPStart, @dianb + ) --第三个点的下标 set @liea = SUBSTRING(@IPStart,,@diana-) --第一列的值
set @lieb =SUBSTRING(@IPStart,@diana+,@dianb-@diana- )--第二列的值
set @liec =SUBSTRING(@IPStart,@dianb+,@dianc-@dianb- )--第三列的值
set @lied =SUBSTRING(@IPStart,@dianc+, LEN(@IPStart))--第四列的值
set @intlon= @lied+(@liec*)+(@lieb*)+(@liea*) --拼为整数 declare @inta bigint
set @inta=(select top IP3 from I_IPCity where IP3>@intlon and IPStart is not null and IPID is not null and IP3 is not null order by IP3 asc)
select top * from I_IPCity where IP3<@inta and IPStart is not null and IPID is not null and IP3 is not null order by IP3 desc --返回'61.177.117.6'在表中对应的数据
END
exec ProIP '61.177.117.6'
说明:
'Arg.ea' 对应位置
:
charindex('.','Arg.ea') > --如果大于零,则表示字符串Area中含有字符串CityName; 此例为true
charindex('.','Arg.ea', ) -- 从第二个位置后,也就是从 字母'r'后开始找,先判断 ‘g’是否为‘.’ ,为否;继续判断‘.’是否为‘.’,此表达式为true
SUBSTRING('Arg.ea',,) --截取 字符串 'Arg.ea'中 第一个位置到第二个位置 ;也就是‘Ar’
IP地址转化为数字,charindex ,SUBSTRING的更多相关文章
- [转]字符型IP地址转换成数字IP的SQL函数
使用SQL函数可以实现许多的功能,下面为您介绍的是字符型IP地址转换成数字IP的SQL函数示例,供您参考,希望对您学习SQL函数能够有所帮助. /**//*--调用示例 sele ...
- 【Go】IP地址转换:数字与字符串之间高效转换
转载:https://blog.thinkeridea.com/201903/go/ip2long.html IP 地址库中 IP 地址的保存格式一般有两种,一种是点分十进制形式(192.168.1. ...
- 将IP地址转化为整数
$ip = 'IP地址';echo $intip = sprintf('%u',ip2long($ip)); //转换为无符号整型echo long2ip($intip);//将整型转换为ip
- ip地址转化代码实例
/*@author: lgh@ * * */ #include <stdio.h> #include <string.h> #include <unistd.h> ...
- 数字转IP地址函数
--------------------------------------------------------------------- -- Author : htl258(Tony) -- Da ...
- (C#)IP地址与数字地址相互转换
站长网IP查询地址:http://tool.chinaz.com/ip/ 和ip地址转换为数字的工具地址:http://www.msxindl.com/tools/ip/ip_num.asp 可以看到 ...
- 域名转化到IP地址的实现
在linux中,有一些函数可以实现主机名和地址的转化,最常见的有gethostbyname().gethostbyaddr()等,它们都可以实现IPv4和IPv6的地址和主机名之间的转化.其中geth ...
- IP地址与数字地址相互转换
/// <summary> /// IP地址转换成数字 /// </summary> /// <param name="addr">IP地址&l ...
- C# 获取本机IP地址以及转换字符串
/// <summary> /// IP地址转化 /// </summary> /// <param name="ipaddr">整型的IP地址 ...
随机推荐
- OData + jqgrid 部署在IIS 8.0上可增加但不能删除修改问题
解决方法: <system.webServer>里添加 <modules> <remove name="WebDAVModule" /> < ...
- VS命令行的使用
CD 命令是改变当前路径,但是它不会改变当前盘符,改变盘符要输入 [盘符]: 命令. 如下: Setting environment for using Microsoft Visual Studio ...
- 快速搭建一个本地的FTP服务器 win10及win7
快速搭建一个本地的FTP服务器 如果需要开发FTP文件上传下载功能,那么需要在本机上搭建一个本地FTP服务器,方便调试. (win10) 第一步:配置IIS Web服务器 1.1 控制面板中找到“ ...
- Python数据结构2-----队列和堆
一.线性结构:栈.队列.双端队列.列表 二.非线性结构:树.图.堆 [算法中看堆是非线性的,因为其相当于完全二叉树,但堆的存储元素是采用线性的顺序表数组来实现的] 三.队列: 1.队列类型:FIFO. ...
- GCJ 2008 Round 1A Minimum Scalar Product( 水 )
链接:传送门 题意:给两个向量 v1 = { x1 , x2 , x3 , x4 .... } , v2 = { y1 , y2 , y3 , y4 ...... } 允许任意交换 v1 和 v2 各 ...
- POJ 1061 青蛙的约会( 拓欧经典题 )
链接:传送门 思路:简单拓展欧几里德,分析后可以得到方程 x + m * t = y + n * t + L * s( s控制圈数,t代表跳t次会碰面 ),经过化简可以得到 ( n - m ) * t ...
- [Libre 6281] 数列分块入门 5 (分块)
水一道入门分块qwq 题面:传送门 开方基本暴力.. 如果某一个区间全部都开成1或0就打上标记全部跳过就行了 因为一个数开上个四五六次就是1了所以复杂度能过233~ code: //By Menteu ...
- mysql 每个月创建新表
1.CREATE DEFINER=`root`@`%` PROCEDURE `aa`()BEGIN SET @sqlstr = CONCAT('create table cdrpbx10_',DATE ...
- Charles抓包工具抓取HTTS请求
1. 移动端(手机)配置证书 1.1 进入Charles,点击Help,选择SSL Proxying --> 选择安装手机证书 1.2 在Charles弹框提示中,按照提示内容,进入手机进入下图 ...
- struct 模块简介
用处 按照指定格式将Python数据转换为字符串,该字符串为字节流,如网络传输时,不能传输int,此时先将int转化为字节流,然后再发送; 按照指定格式将字节流转换为Python指定的数据类型; 处理 ...