function HZOffset(fHZ: string): integer;
begin
if length(fHZ) >= 2 then
Result := (Ord(fHZ[1]) - 161) * 94 + (Ord(fHZ[2]) - 161)
else
Result := -1;
end;
怎樣將上面DELPHI計算漢字機器碼的代碼在SQL中實現, 謝謝各位大哥
...全文
2812打赏收藏
怎樣在SQL內將漢字的機器碼折分出來
function HZOffset(fHZ: string): integer; begin if length(fHZ) >= 2 then Result := (Ord(fHZ[1]) - 161) * 94 + (Ord(fHZ[2]) - 161) else Result := -1; end; 怎樣將上面DELPHI計算漢字機器碼的代碼在SQL中實現, 謝謝各位大哥
CREATE FUNCTION [dbo].[HZOffset] (@fHZ varchar(10))
RETURNS int
AS
begin
declare @Result int
if datalength(@fHZ)>= 2
set @Result=(cast(cast(@fHZ as varbinary) as int)/256-161)*94+(cast(cast(@fHZ as varbinary) as int)%256-161)
else
set @Result=-1
return @Result
end