将ms sql函数转换为mysql函数

ar5n3qh5  于 2021-06-21  发布在  Mysql
关注(0)|答案(0)|浏览(224)

我正在尝试将这个mssql函数转换为mysql,但是我有语法错误。
错误:syntaz错误:意外的“int”(int)
ms sql函数:

CREATE FUNCTION [dbo].[f_ConvertIPV6to4]
(@AddrIPV6 varchar(50))
RETURNS varchar(17)

AS

BEGIN

declare @ipv4 varchar(17)

set @ipv4 = (
select
cast(convert(int, convert(varbinary, '0x' + substring(substring(@AddrIPV6, (len(@AddrIPV6)-charindex(':', @AddrIPV6)) - 3, 4), 1, 2), 1)) as varchar(3)) + '.' +
cast(convert(int, convert(varbinary, '0x' + substring(substring(@AddrIPV6, (len(@AddrIPV6)-charindex(':', @AddrIPV6)) - 3, 4), 3, 2), 1)) as varchar(3)) + '.' +
cast(convert(int, convert(varbinary, '0x' + substring(substring(@AddrIPV6, (len(@AddrIPV6)-charindex(':', @AddrIPV6)) + 2, 4), 1, 2), 1)) as varchar(3)) + '.' +
cast(convert(int, convert(varbinary, '0x' + substring(substring(@AddrIPV6, (len(@AddrIPV6)-charindex(':', @AddrIPV6)) + 2, 4), 3, 2), 1)) as varchar(3))
)
return @ipv4

END

GO

mysql函数:

CREATE FUNCTION f_ConvertIPV6to4
(p_AddrIPV6 varchar(50))
RETURNS varchar(17)

BEGIN

declare v_ipv4 varchar(17);

set v_ipv4 = (
select
cast(convert(int, convert(varbinary, Concat('0x' , substring(substring(p_AddrIPV6, (char_length(rtrim(p_AddrIPV6))-charindex(':', p_AddrIPV6)) - 3, 4), 1, 2)), 1)) as varchar(3)) + '.' +
cast(convert(int, convert(varbinary, Concat('0x' , substring(substring(p_AddrIPV6, (char_length(rtrim(p_AddrIPV6))-charindex(':', p_AddrIPV6)) - 3, 4), 3, 2)), 1)) as varchar(3)) + '.' +
cast(convert(int, convert(varbinary, Concat('0x' , substring(substring(p_AddrIPV6, (char_length(rtrim(p_AddrIPV6))-charindex(':', p_AddrIPV6)) + 2, 4), 1, 2)), 1)) as varchar(3)) + '.' +
cast(convert(int, convert(varbinary, Concat('0x' , substring(substring(p_AddrIPV6, (char_length(rtrim(p_AddrIPV6))-charindex(':', p_AddrIPV6)) + 2, 4), 3, 2)), 1)) as varchar(3))
)
return v_ipv4;

END

请任何人帮我解决这个问题。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题