--数字转IP地址函数:
IF OBJECT_ID('dbo.fn_IP2Str')>0
DROP FUNCTION dbo.fn_IP2Str
GO
CREATE FUNCTION [dbo].[fn_IP2Str] (
@InIP BIGINT
)
RETURNS NVARCHAR(15)
AS
BEGIN
IF @InIP IS NULL
RETURN '0.0.0.0'
DECLARE @ip BIGINT
SET @ip = @InIP
SET @ip = @ip + 0x100000000
RETURN
CAST(((@ip & 0xff000000) / 0x1000000) AS NVARCHAR(3)) + '.' +
CAST(((@ip & 0xff0000) / 0x10000) AS NVARCHAR(3)) + '.' +
CAST(((@ip & 0xff00) / 0x100) AS NVARCHAR(3)) + '.' +
CAST((@ip & 0xff) AS NVARCHAR(3))
END
GO
--调用示例:
SELECT dbo.fn_IP2Str(4294967295)
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
IF OBJECT_ID('dbo.f_Int2IP')>0
DROP FUNCTION dbo.f_Int2IP
CREATE FUNCTION f_Int2IP
(
@IP BIGINT
)
RETURNS VARCHAR(15)
AS
BEGIN
DECLARE @re VARCHAR(16)
SET @re = ''
SELECT @re = @re+'.'+CAST(@IP/ID AS VARCHAR), @IP = @IP%ID
FROM (
SELECT ID = CAST(16777216 AS BIGINT)
UNION ALL SELECT 65536
UNION ALL SELECT 256
UNION ALL SELECT 1
)a
RETURN(STUFF(@re, 1, 1, ''))
END
GO
--调用示例:
select dbo.f_Int2IP(333444343)
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
获取IP地址
端点(API接口)访问获取IP地址!
IP Java SpringBoot\ -
数字转IP地址自定义函数(附:相互转换)
数字转IP地址自定义函数(附:相互转换)
microsoft function sql server object go -
数字IP 与 ip地址转换
数字IP 与 ip地址转换
ip 地址转换 数字IP -
vue element html组件
setup 中实现响应式数据<template> <img alt="Vue logo" src="./assets/logo.png"> <h2>a:`a`</h2> <button @click="add">vue3</button> </template> <script> im
vue element html组件 vue.js elementui javascript 数据