2016-10-25 86 views
1

我最近遇到了下面的函数来在计算器:执行一个功能。无法打印输出

CREATE FUNCTION dbo.UrlDecode(@url varchar(3072)) 
RETURNS varchar(3072) 
AS 
BEGIN 
    DECLARE @count int, @c char(1), @cenc char(2), @i int, @urlReturn varchar(3072) 
    SET @count = Len(@url) 
    SET @i = 1 
    SET @urlReturn = '' 
    WHILE (@i <= @count) 
    BEGIN 
     SET @c = substring(@url, @i, 1) 
     IF @c LIKE '[!%]' ESCAPE '!' 
     BEGIN 
      SET @cenc = substring(@url, @i + 1, 2) 
      SET @c = CHAR(CASE WHEN SUBSTRING(@cenc, 1, 1) LIKE '[0-9]' 
           THEN CAST(SUBSTRING(@cenc, 1, 1) as int) 
           ELSE CAST(ASCII(UPPER(SUBSTRING(@cenc, 1, 1)))-55 as int) 
          END * 16 + 
          CASE WHEN SUBSTRING(@cenc, 2, 1) LIKE '[0-9]' 
           THEN CAST(SUBSTRING(@cenc, 2, 1) as int) 
           ELSE CAST(ASCII(UPPER(SUBSTRING(@cenc, 2, 1)))-55 as int) 
          END) 
      SET @urlReturn = @urlReturn + @c 
      SET @i = @i + 2 
     END 
     ELSE 
     BEGIN 
      SET @urlReturn = @urlReturn + @c 
     END 
     SET @i = @i +1 
    END 
    RETURN @urlReturn 
END 
GO 


I am trying to pass the following URL as an input to get the decoded URL as output using the following command: 

DECLARE @urlReturn nvarchar(3072); 
EXEC dbo.UrlDecode2 @url = 'https%3a%2f%2fin.mathworks.com'; 
PRINT @urlReturn; 
GO 

最初尝试了以下内容:

exec dbo.UrlDecode2 @url = 'https%3a%2f%2fin.mathworks.com'; 
go 

功能的URL解码编码的部分。我对PL/SQL完全陌生。有人能告诉我我哪里出错了,以及如何打印解码的URL。

+0

请正确格式化你的代码。您可以通过将每行缩进4个空格或突出显示代码并按ctrl + k来完成此操作。 – Carcigenicate

+0

代码是如此清晰的SQL Server,我删除了PL/SQL标签。如果你真的使用Oracle,你应该让自己有另一个功能。 –

回答

0
Declare @URL varchar(500) 
Set @URL = dbo.UrlDecode2('https%3a%2f%2fin.mathworks.com') 

返回

https://in.mathworks.com 

或者内选择

Select URL = dbo.UrlDecode2('https%3a%2f%2fin.mathworks.com') 
+0

谢谢!这是正确的。 – Dilip