如何在Oracle上生成版本4(随机)的UUID? [英] How to generate a version 4 (random) UUID on Oracle?

查看:660
本文介绍了如何在Oracle上生成版本4(随机)的UUID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此博客解释说,sys_guid()的输出并非在每个系统上都是随机的:

This blog explains, that the output of sys_guid() is not random for every system:

http://feuerthoughts.blogspot. de/2006/02/watch-out-for-sequential-oracle-guids.html

不幸的是,我必须使用这样的系统.

Unfortunately I have to use such a system.

如何确保获得随机UUID? sys_guid()是否可能?如果不是,如何在Oracle上可靠地获取随机UUID?

How to ensure to get a random UUID? Is it possible with sys_guid()? If not how to reliably get a random UUID on Oracle?

推荐答案

我现在将其用作解决方法:

I use this now as a workaround:


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.两者都需要执行授权.

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

grant execute on sys.dbms_crypto to uuid_user;

这篇关于如何在Oracle上生成版本4(随机)的UUID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆