Oracle 的 SYS_GUID() UUID RFC 4122 是否兼容?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6505837/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is Oracle's SYS_GUID() UUID RFC 4122 compliant?
提问by nulldevice
I wonder if Oracle's SYS_GUID() function returns a RFC 4122 compliant UUID. For example:
我想知道 Oracle 的 SYS_GUID() 函数是否返回符合 RFC 4122 的 UUID。例如:
SQL> select sys_guid() from dual;
SYS_GUID()
--------------------------------
A6C1BD5167C366C6E04400144FD25BA0
I know, that SYS_GUID() returns a 16 byte RAW datatype. Oracle uses RAWTOHEX() and probably TO_CHAR() to print out the above ID. Is it correct to interpret this as a UUID compliant string format like:
我知道,SYS_GUID() 返回一个 16 字节的 RAW 数据类型。Oracle 使用 RAWTOHEX() 和可能的 TO_CHAR() 打印出上述 ID。将此解释为符合 UUID 的字符串格式是否正确,例如:
A6C1BD51-67C3-66C6-E044-00144FD25BA0
I think it's not compliant to the RFC 4122 standard, because the definition says, that a valid UUID must name the UUID-Version within the UUID itself.
我认为它不符合 RFC 4122 标准,因为定义说,有效的 UUID 必须在 UUID 本身内命名 UUID-Version。
Syntax for a RFC 4122 compliant UUID (Version 3):
符合 RFC 4122 的 UUID(版本 3)的语法:
xxxxxxxx-xxxx-3xxx-xxxx-xxxxxxxxxxxx
采纳答案by APC
SYS_GUID is Oracle's equivalentof 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).
SYS_GUID相当于Oracle 的UUID。它是全球独一无二的。但是,它不符合 RFC 4122;我从文档中(在 Java XML 文档之外)中没有对 UUID 的引用推断出缺乏合规性。
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.
我怀疑 Oracle 没有在本地实现 RFC 4122,因为他们认为它无法扩展。我无法想象为什么他们会发明自己的东西而不是遵守标准。
回答by 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})'
, '----')
as FORMATTED_GUID
from dual
Example Results:
结果示例:
FORMATTED_GUID
------------------------------------
F680233E-0FDD-00C4-E043-0A4059C654C9
回答by NealeU
With sufficient privileges, it is possible to have Oracle generate compliant UUIDs.
拥有足够的权限,就可以让 Oracle 生成兼容的 UUID。
1. By defining a SQL function
1.通过定义一个SQL函数
From https://stackoverflow.com/a/13956771, you can do the following:
从https://stackoverflow.com/a/13956771,您可以执行以下操作:
创建或替换函数 random_uuid 返回 RAW 是 v_uuid RAW(16); 开始 v_uuid := sys.dbms_crypto.randombytes(16); 返回 (utl_raw.overlay(utl_raw.bit_or(utl_raw.bit_and(utl_raw.substr(v_uuid, 7, 1), '0F'), '40'), v_uuid, 7)); 结束 random_uuid;
The function requires dbms_crypto
and utl_raw
. Both require an execute grant.
该函数需要dbms_crypto
和utl_raw
。两者都需要执行授权。
grant execute on sys.dbms_crypto to uuid_user;
2. Using a Java procedure
2. 使用 Java 过程
To create a Java procedure for creating a compliant UUID, see https://stackoverflow.com/a/13951615.
要创建用于创建兼容 UUID 的 Java 过程,请参阅https://stackoverflow.com/a/13951615。