tags:

views:

1127

answers:

3

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.

+4  A: 

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.

Anonymous
Good eyes! I think this is the problem that the think I posted is talking about though.
Greg Reynolds
+6  A: 

The value does change....

           *
64FE4083D6BA7CB4E0400F0A0E0A18B0
64FE4083D6BB7CB4E0400F0A0E0A18B0
64FE4083D6BC7CB4E0400F0A0E0A18B0
64FE4083D6BD7CB4E0400F0A0E0A18B0
64FE4083D6BE7CB4E0400F0A0E0A18B0
           *
cagcowboy
Thanks - I feel stupid now...
Greg Reynolds
:-) We've all been there.... you can stare at something for an hour and not spot something that a colleague then spots in 5 seconds.
cagcowboy
Nice use of formatting.
Gary
+1  A: 

Greg: Don't feel too stupid. I found the same 'error' and if it was not for your post I would have been chasing my tail for a while.

The guids below ARE different:

84D0B3E1E4DD6E8AE040800AAE1B2D96

84D0B3E1E4D26E8AE040800AAE1B2D96

84D0B3E1E4C66E8AE040800AAE1B2D96

84D0B3E1E4BA6E8AE040800AAE1B2D96

Thanks :)

Garth
No problem - happy that you don't have to repeat my mistake!
Greg Reynolds