Note that there are some explanatory texts on larger screens.

plurals
  1. POOracle GUIDTORAW and RAWTOGUID function endianness
    primarykey
    data
    text
    <p>My app internally uses RAW(16) guids generated via sys_guid().<br> Recently I started associating Active Directory users where I get guid's in the format of: 00000000-0000-0000-0000-00000000000</p> <p>Are the following two functions doing this conversion correctly?</p> <p>Found the following site:</p> <p><a href="http://www.timvasil.com/blog14/post/2009/01/20/User-defined-function-to-convert-from-RAW(16)-to-a-GUID-in-Oracle.aspx" rel="noreferrer">http://www.timvasil.com/blog14/post/2009/01/20/User-defined-function-to-convert-from-RAW(16)-to-a-GUID-in-Oracle.aspx</a></p> <pre><code>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; </code></pre> <p>Adding in the following site:</p> <p><a href="http://dbaspot.com/oracle-server/69226-guid-char-conversion-function.html" rel="noreferrer">http://dbaspot.com/oracle-server/69226-guid-char-conversion-function.html</a></p> <p>Came up with this function to do the inverse:</p> <pre><code>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; </code></pre> <p>They convert back and forth, but am I actually respecting the endianness or have the right order at all?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload