在SQL如何将一个长度是10位bigint型的数值转换成IP形式

发布网友

我来回答

3个回答

热心网友

将长整型转换为IP地址

Name: Convert LongIP to StringIP
Description: This function converts a Long Number (3232235521) into an IP Address ("192.168.0.1"). Why would you want to do this? Click here.
Inputs: anNewIP - IP Address as a Long Number (no dots)

Returns: Returns the string representation of an IP Address ("192.168.0.1")

Function CStrIP(ByVal anNewIP)
Dim lsResults ' Results To be returned
Dim lnTemp ' Temporary value being parsed
Dim lnIndex ' Position of number being parsed
' If pulling number from an Access Database,
' The variable Type "Long" ranges from -21474838 To 21474837
' You will first need To add 21474838 to the number to parse correctly.
' anNewIP = anNewIP + 21474838
' Parse highest numbers first
For lnIndex = 3 To 0 Step -1

' Parse the current value For this position
lnTemp = Int(anNewIP / (256 ^ lnIndex))

' Append the number To the final results delimited by a dot
lsResults = lsResults & lnTemp & "."

' Remove the number that we just parsed
anNewIP = anNewIP - (lnTemp * (256 ^ lnIndex))

Next

' Cut off last dot
lsResults = Left(lsResults, Len(lsResults) - 1)

' Return the results
CStrIP = lsResults

End Function

热心网友

为什么不用varchar储存呢一开始

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com