oracle生成uuid
时间:2022-03-13 22:56
select sys_guid() from dual;
-->78AE331ADB2B4CE7AB598B1317B39D58
但该函数如下问题:
为了使产生的uuid符合rfc 4122的标准
创建函数如下,测试通过。
create or replace function get_uuid return varchar2 is
v_uuid varchar(36);
begin
v_uuid := lower(rawtohex(sys_guid()));
v_uuid := substr(v_uuid, 1, 8) || ‘-‘ || substr(v_uuid, 9, 4) || ‘-‘ ||
substr(v_uuid, 13, 4) || ‘-‘ || substr(v_uuid, 17, 4) || ‘-‘ ||
substr(v_uuid, 21, 12);
return v_uuid;
end get_uuid;
select get_uuid() from dual ;
-->7bb0152a-4c5c-4078-a1b8-f57ae58254e5