亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

快速將珊瑚蟲(chóng)IP數(shù)據(jù)庫(kù)轉(zhuǎn)MS SQL2005的圖文教程第2/2頁(yè)

 更新時(shí)間:2008年08月02日 01:52:46   作者:  
在幻想曲BLOG上看到不少朋友說(shuō),最近服務(wù)器上的IP數(shù)據(jù)好像不是很準(zhǔn)確,于是重新做了一個(gè)新的,不少朋友可能需要這個(gè)數(shù)據(jù)庫(kù),因?yàn)槲募蟮木壒剩灾苯犹峁┛焖俎D(zhuǎn)換方法。

復(fù)制代碼 代碼如下:

-- 建立IP轉(zhuǎn)換到十進(jìn)制方法 
USE [BasName] 
GO 
/****** 對(duì)象:  UserDefinedFunction [dbo].[X16ToDe]    腳本日期: 09/19/2007 13:56:15 ******/ 
SET ANSI_NULLS ON 
GO 
SET QUOTED_IDENTIFIER ON 
GO 

-- ============================================= 
-- Author:        <Author,,Name> 
-- Create date: <Create Date, ,> 
-- Description:    轉(zhuǎn)換IP為十進(jìn)制 
-- ============================================= 
Create FUNCTION [dbo].[X16ToDe] 

    @Old_IP nvarchar(15) 

RETURNS numeric 
AS 
BEGIN 
    DECLARE 
        @CharIndex INT, 
        @CurrPoint INT, 
        @SingleValue NVARCHAR(5), 
        @Cache numeric 

    SET @CharIndex = 1 
    SET @CurrPoint = CHARINDEX('.',@Old_IP,@CharIndex) 
    SET @SingleValue = SUBSTRING(@Old_IP,@CharIndex,@CurrPoint - @CharIndex) 
    SET @Cache = cast(@SingleValue as numeric)*16777216 

    SET @CharIndex = @CurrPoint + 1 
    SET @CurrPoint = CHARINDEX('.',@Old_IP,@CharIndex) 
    SET @SingleValue = SUBSTRING(@Old_IP,@CharIndex,@CurrPoint - @CharIndex) 
    SET @Cache = @Cache + cast(@SingleValue as numeric)*65536 

    SET @CharIndex = @CurrPoint + 1 
    SET @CurrPoint = CHARINDEX('.',@Old_IP,@CharIndex) 
    SET @SingleValue = SUBSTRING(@Old_IP,@CharIndex,@CurrPoint - @CharIndex) 
    SET @Cache = @Cache + cast(@SingleValue as numeric)*256 

    SET @CharIndex = @CurrPoint + 1 
    SET @SingleValue = SUBSTRING(@Old_IP,@CharIndex,len(@Old_IP)- @CharIndex + 1) 
    SET @Cache = @Cache + cast(@SingleValue as numeric) 

    RETURN @Cache; 
END 

復(fù)制代碼 代碼如下:

-- 建立十進(jìn)制新表 
USE [BasName] 
GO 
/****** 對(duì)象:  Table [dbo].[IP_Real]    腳本日期: 09/19/2007 14:01:31 ******/ 
SET ANSI_NULLS ON 
GO 
SET QUOTED_IDENTIFIER ON 
GO 
Create TABLE [dbo].[IP_Real]( 
    [startip] [numeric](18, 0) NULL, 
    [endip] [numeric](18, 0) NULL, 
    [country] [nvarchar](50) NULL, 
    [local] [nvarchar](200) NULL 
) ON [PRIMARY] 



這一步你可以自己按照你的情況來(lái)做,我是為了加快數(shù)據(jù)庫(kù)索引的速度,所以將IP全部轉(zhuǎn)換為十進(jìn)制,存到一個(gè)新表里面。

-- 格式化省份
復(fù)制代碼 代碼如下:

Update [BasName].[dbo].[IP] 
   SET [country] = replace([country],N'省',N'省 ') 

-- 刪除CZ88.NET
復(fù)制代碼 代碼如下:

Update [BasName].[dbo].[IP] 
   SET [country] = replace([country],N'CZ88.NET',N'') 

-- 將地區(qū)提出
Update [BasName].[dbo].[IP]
   SET [local] = SUBSTRING([country],CHARINDEX(' ',[country],1)+1,len([country]))

-- 存為國(guó)家或省份
Update [BasName].[dbo].[IP]
   SET [country] = SUBSTRING([country],0,CHARINDEX(' ',[country],1))

-- 去處前后導(dǎo)空格
Update [BasName].[dbo].[IP]
   SET [country] = Rtrim(Ltrim([country]))
      ,[local] = Rtrim(Ltrim([local]))

-- 轉(zhuǎn)換IP為十進(jìn)制,并寫(xiě)入新表
Insert INTO [BasName].[dbo].[IP_Real]
           ([startip]
           ,[endip]
           ,[country]
           ,[local])
Select dbo.X16ToDe([startip])
      ,dbo.X16ToDe([endip])
      ,[country]
      ,[local]
  FROM [BasName].[dbo].[IP]
order by [startip] ASC



最后測(cè)試一下看看:

 程序代碼

-- 測(cè)試
DECLARE @IPNumber numeric
set @IPNumber = dbo.X16ToDe('219.140.31.91')

Select [startip]
      ,[endip]
      ,[country]
      ,[local]
  FROM [BasName].[dbo].[IP_Real]
Where [startip] <= @IPNumber and [endip] >= @IPNumber



基本所有的轉(zhuǎn)換最多3分鐘完成,比自己寫(xiě)應(yīng)用程序轉(zhuǎn)換要快的多。

相關(guān)文章

最新評(píng)論