Is Oracle's SYS_GUID() UUID RFC 4122 compliant?

拈花ヽ惹草 提交于 2019-11-28 07:22:57

SYS_GUID is Oracle's equivalent of UUID. It is globally unique. However, it is not compliant to RFC 4122; I'm inferring lack of compliance from the absence of references to UUID in the documentation (outside the Java XML documentation).

I suspect Oracle haven't natively implemented RFC 4122 because they don't think it scales. I can't imagine why else they would invent their own thing instead of complying to a standard.

scottrudy

If you want that format try this:

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 FORMATTED_GUID 
 from dual

Example Results:

 FORMATTED_GUID                                                                  
 ------------------------------------
 F680233E-0FDD-00C4-E043-0A4059C654C9  
NealeU

With sufficient privileges, it is possible to have Oracle generate compliant UUIDs.

1. By defining a SQL function

From https://stackoverflow.com/a/13956771, you can do the following:

create or replace function random_uuid return RAW is
  v_uuid RAW(16);
begin
  v_uuid := sys.dbms_crypto.randombytes(16);
  return (utl_raw.overlay(utl_raw.bit_or(utl_raw.bit_and(utl_raw.substr(v_uuid, 7, 1), '0F'), '40'), v_uuid, 7));
end random_uuid;

The function requires dbms_crypto and utl_raw. Both require an execute grant.

grant execute on sys.dbms_crypto to uuid_user;

2. Using a Java procedure

To create a Java procedure for creating a compliant UUID, see https://stackoverflow.com/a/13951615.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!