我的应用程序内部使用通过 sys_guid() 生成的 RAW(16) guid。
最近我开始关联 Active Directory 用户,我在其中获得 guid,格式为:00000000-0000-0000-0000-00000000000
以下两个函数是否正确执行此转换?
找到以下网站:
create or replace
FUNCTION RAWTOGUID
( RawData IN RAW
) RETURN VARCHAR AS
BEGIN
declare HexData varchar(32) := rawtohex(RawData);
begin
return
substr(HexData, 7, 2)
|| substr(HexData, 5, 2)
|| substr(HexData, 3, 2)
|| substr(HexData, 1, 2)
|| '-'
|| substr(HexData, 11, 2)
|| substr(HexData, 9, 2)
|| '-'
|| substr(HexData, 15, 2)
|| substr(HexData, 13, 2)
|| '-'
|| substr(HexData, 17, 4)
|| '-'
|| substr(HexData, 21, 12);
end;
END RAWTOGUID;
在以下站点中添加:
http://dbaspot.com/oracle-server/69226-guid-char-conversion-function.html
想出了这个函数来做相反的事情:
create or replace
FUNCTION GUIDTORAW
( HexData IN VARCHAR
) RETURN RAW AS
BEGIN
declare StringData varchar(32) := TRANSLATE(HexData,'0{-}','0');
begin
return
hextoraw(substr(StringData, 7, 2)
|| substr(StringData, 5, 2)
|| substr(StringData, 3, 2)
|| substr(StringData, 1, 2)
|| substr(StringData, 11, 2)
|| substr(StringData, 9, 2)
|| substr(StringData, 15, 2)
|| substr(StringData, 13, 2)
|| substr(StringData, 17, 4)
|| substr(StringData, 21, 12));
end;
END GUIDTORAW;
他们来回转换,但我真的尊重字节序还是有正确的顺序?