首页 > 解决方案 > Delphi ORD、SHL 和 SHR 函数 SQL Server 的等效项是什么?

问题描述

我有 2 个 Delphi 函数需要迁移到 SQL Server,但我不确定 ORD、SHL 和 SHR 函数的等效项。有人可以帮助了解这些 Delphi 函数在 SQL 中的样子吗?

function QX_Encrypt(s:String) : String;
var 
    sTempString : string;
    iIndex , i: integer;
begin
    sTempString  := s ;
    for iIndex := 1 to length(sTempString) do
    begin
        i := ord(sTempString[iIndex]);
        i:= i shl 1;
        sTempString[iIndex] := char(i) ;
    end;
    result := stempstring;
end;

function QX_Decrypt(s:String) : String;
var 
    sTempString : string;
    iIndex , i : integer;
begin
    sTempString  := s ;
    for iIndex := 1 to length(sTempString) do
    begin
        i := ord(sTempString[iIndex]);
        i:= i shr 1;
        sTempString[iIndex] := char(i) ;
    end;
    result := sTempString;
end;

标签: sql-serverdelphi

解决方案


感谢您的指导。这是一个片段,它做了我想要的。

DECLARE 
    @cnt INT = 1,
    @Password nvarchar(20) = 'P@ssword1',
    @NewPassword nvarchar(20)
WHILE @cnt < LEN(@Password) + 1
BEGIN
    SELECT @NewPassword = CONCAT(@NewPassword, CHAR(ASCII(SUBSTRING(@Password, @cnt, 1)) * 2))
    SET @cnt = @cnt + 1;
END;
SELECT @NewPassword


推荐阅读