I need to create UUIDs version 4 in the format like xxxxxxxxxxxx-4xxx-yxxx-xxxxxxxxxxxx. (x= any hexadecimal character (lower case only); y is one of 8, 9, a or b; 4 is static)
The best solution for me to do this is in my Oracle database. After some research I found out that SYS_GUID() can be a solution:
select regexp_replace(rawtohex(sys_guid()), '([A-F0-9]{8})([A-F0-9]{4})([A-F0-9]{4})([A-F0-9]{4})([A-F0-9]{12})', '\1-\2-\3-\4-\5') as UUID from dual;
But the result is not what I expect:
UUID
------------------------------------
712EE4F7-823E-AD73-E053-8E3A220A3EFB
So the "4" at position 13 and "y" at position 17 are not correct in my example. Any other/better ways to create an UUID or why is SYS_GUID returning an other format?