Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle SYS_GUID does not change

Tags:

guid

oracle

I have an Oracle project that would be a good fit for using GUIDs as a key. I found the following snippet

SET SERVEROUTPUT ON
BEGIN
FOR indx IN 1 .. 5
LOOP
DBMS_OUTPUT.put_line ( SYS_GUID );
END LOOP;
END;
/

From http://feuerthoughts.blogspot.com/2006/02/watch-out-for-sequential-oracle-guids.html

When I run it against my database (I tried it on versions 10g and version 11) I get output like

64FE4083D6BA7CB4E0400F0A0E0A18B0
64FE4083D6BB7CB4E0400F0A0E0A18B0
64FE4083D6BC7CB4E0400F0A0E0A18B0
64FE4083D6BD7CB4E0400F0A0E0A18B0
64FE4083D6BE7CB4E0400F0A0E0A18B0

I.e. the value never changes! Is there something I have to do to set this up to work as expected?

Edit: I am not very observant - the GUIDs are changing, but it looks like I am suffering from the sequential GUID problem that the link above is talking about.

like image 334
Greg Reynolds Avatar asked Mar 13 '09 10:03

Greg Reynolds


1 Answers

Seems OK. From the description:

SYS_GUID generates and returns a globally unique identifier (RAW value) made up of 16 bytes. On most platforms, the generated identifier consists of a host identifier, a process or thread identifier of the process or thread invoking the function, and a nonrepeating value (sequence of bytes) for that process or thread.

From your example:

64FE4083D6BA7CB4E0400F0A0E0A18B0
64FE4083D6BB7CB4E0400F0A0E0A18B0
64FE4083D6BC7CB4E0400F0A0E0A18B0
64FE4083D6BD7CB4E0400F0A0E0A18B0
64FE4083D6BE7CB4E0400F0A0E0A18B0

Nobody mentioned anything about the distribution of these GUID values. They should be nonrepeating and they are. Unless you get exactly the same output every time.

like image 199
Anonymous Avatar answered Oct 10 '22 10:10

Anonymous