1. 程式人生 > >MSSQL 字串轉成16進位制函式

MSSQL 字串轉成16進位制函式

分享一下我老師大神的人工智慧教程!零基礎,通俗易懂!http://blog.csdn.net/jiangjunshow

也歡迎大家轉載本篇文章。分享知識,造福人民,實現我們中華民族偉大復興!

                 
/**************************** 字串轉成16進製作者:不得閒QQ: 75492895Email: [email protected]
****************************/--建立函式(suiyunonghen(不得閒)) 
Create Function VarCharToHex(@Str Varchar(400))returns varchar(800)asbegindeclare @i int,@Asi int,@ModS int,@res varchar(800),@Len int,@Cres varchar(4),@tempstr varbinary(400)select @i = 1,@res='',@len=datalength(@str),@tempStr = Convert(varbinary,@str)while @i<[email protected]len beginSelect @Asi = substring
(@tempstr,1,1),@Cres=''while @Asi <> 0beginselect @Mods = @Asi %16,@Cres=Case when (@Mods > 9) then Char(Ascii('A')[email protected]-10)[email protected] else Cast(@Mods as varchar(4)) + @Cres end,@Asi = @Asi/16end Select @res = @res + @Cres,@tempStr = substring(@tempStr,2,@len-1),@i = @i+1
endreturn @resendgo--測試示例select dbo.VarCharToHex('葉子')--執行結果/*D2B6D7D3*/

           

給我老師的人工智慧教程打call!http://blog.csdn.net/jiangjunshow

這裡寫圖片描述