if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[inet_ntoa]’) and xtype in (N’FN’, N’IF’, N’TF’))
drop function [dbo].[inet_ntoa]
GO
/**//*–整形数字IP转换成点分十进制IP地址–*/
/**//*–调用示例
select dbo.[inet_ntoa](3232235531)
select dbo.[inet_ntoa](212336641)
–*/
CREATE FUNCTION [inet_ntoa](
@IP bigint
)RETURNS varchar(15)
AS
BEGIN
DECLARE @re varchar(15)
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
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[inet_aton]’) and xtype in (N’FN’, N’IF’, N’TF’))
drop function [dbo].[inet_aton]
GO
/**//*–点分十进制IP地址转换成整形数字IP –*/
/**//*–调用示例
select dbo.inet_aton(’192.168.0.11′)
select dbo.inet_aton(’12.168.0.1′)
–*/
CREATE FUNCTION [dbo].[inet_aton](
@IP bigint
)RETURNS varchar(15)
AS
BEGIN
DECLARE @re varchar(15)
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
0 条评论。