How to generate a version 4 (random) UUID on Oracle?

前端 未结 9 1093
野性不改
野性不改 2020-12-05 10:37

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-orac

9条回答
  •  再見小時候
    2020-12-05 11:14

    https://stackoverflow.com/a/10899320/1194307

    The following function use sys_guid() and transform it into uuid format:

    create or replace function random_uuid return VARCHAR2 is
      v_uuid VARCHAR2(40);
    begin
      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') into v_uuid from dual;
      return v_uuid;
    end random_uuid;
    

    It do not need create dbms_crypto package and grant it.

提交回复
热议问题