Oracle 的 SYS_GUID() UUID RFC 4122 是否兼容?

发布于 2024-11-17 15:27:33 字数 641 浏览 4 评论 0原文

我想知道 Oracle 的 SYS_GUID() 函数是否返回 符合 RFC 4122 的 UUID。例如:

SQL> select sys_guid() from dual;

SYS_GUID()
--------------------------------
A6C1BD5167C366C6E04400144FD25BA0

我知道 SYS_GUID() 返回 16 字节 RAW 数据类型。 Oracle 使用 RAWTHEX() 和可能的 TO_CHAR() 来打印上面的 ID。将其解释为符合 UUID 的字符串格式是否正确,例如:

A6C1BD51-67C3-66C6-E044-00144FD25BA0

我认为它不符合 RFC 4122 标准,因为定义表示,有效的 UUID 必须在 UUID 本身内命名 UUID 版本。

符合 RFC 4122 的 UUID(版本 3)的语法:

xxxxxxxx-xxxx-3xxx-xxxx-xxxxxxxxxxxx

I wonder if Oracle's SYS_GUID() function returns a RFC 4122 compliant UUID. For example:

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:

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.

Syntax for a RFC 4122 compliant UUID (Version 3):

xxxxxxxx-xxxx-3xxx-xxxx-xxxxxxxxxxxx

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

浪荡不羁 2024-11-24 15:27:33

如果您想要该格式,请尝试以下操作:

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

结果示例:

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

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  
绮筵 2024-11-24 15:27:33

SYS_GUID 是 Oracle 的 UUID等价物。它是全球独一无二的。但是,它不符合 RFC 4122;我从文档中(Java XML 文档之外)没有引用 UUID 来推断缺乏合规性。

我怀疑 Oracle 尚未本地实现 RFC 4122,因为他们认为它无法扩展。我无法想象为什么他们会发明自己的东西而不是遵守标准。

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.

许你一世情深 2024-11-24 15:27:33

有了足够的权限,Oracle 就可以生成兼容的 UUID。

1.通过定义 SQL 函数,

您可以从 https://stackoverflow.com/a/13956771 执行以下操作:

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;

该函数需要 dbms_cryptoutl_raw。两者都需要执行补助金。

grant execute on sys.dbms_crypto to uuid_user;

2.使用 Java 过程

要创建用于创建兼容 UUID 的 Java 过程,请参阅 https://stackoverflow.com/a/13951615< /a>.

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.

桜花祭 2024-11-24 15:27:33

RFC 4122 § 3. 命名空间注册模板(第 5 页)

验证机制:
除了判断UUID的时间戳部分是否
是在未来,因此尚未可分配,没有
确定 UUID 是否“有效”的机制。

生成过程决定了是否“符合”RFC 4122,UUID本身只是一个128位ID实体。

所以答案是肯定的,为什么不合规呢? UUID 只是一个 128 位 U 通用 U 唯一 ID 实体,规范的其余部分只是推荐帮助您/Oracle 生成标识符的方法,这些标识符不会与生成 UU ID 实体的其他系统发生冲突。如果您或 Oracle 不想遵循他们的建议,他们可以随意这样做。无论如何,您提供的 uuid “符合”RFC 4122,因为变体字段以位序列 111 开头,“保留供将来定义”。该规范是在过去编写的,并不限制谁可以指定“未来的定义”,它当然不会阻止 Oracle 定义自己的变体......因此它是“合规性的”......哈哈。

ps 我喜欢原作者如何预见你的问题并在“有效”周围添加讽刺引号。

RFC 4122 § 3. Namespace Registration Template (Page 5)

Validation mechanism:
Apart from determining whether the timestamp portion of the UUID
is in the future and therefore not yet assignable, there is no
mechanism for determining whether a UUID is 'valid'.

It is the generation process that determines "compliance" with RFC 4122, the UUID itself is just a 128 bit IDentifier.

Therefore the answer is yes, why would it not be compliant? A UUID is just an 128 bit Universaly Unique IDentifier, the rest of the spec is just recommended ways to help you/Oracle generate identifiers that do not collide with other systems that generate U.U. IDentifiers. If you or Oracle do not want to follow their recommendations, they are free to do so. Regardless, the uuid you gave is "in compliance" with RFC 4122 as the variant field starts with the bit sequence 111 which is "Reserved for future definition.". The spec was written in the past and does not restrict who can specify a "future definition", it certainly does not prevent Oracle from defining their own variants... therefore it is "in compliance"... lol.

p.s. I love how the original authors anticipated your question and added sarcasm quotes around 'valid'.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文