How to generate a GUID in Oracle?

前端 未结 9 601
悲哀的现实
悲哀的现实 2020-12-04 10:49

Is it possible to auto-generate a GUID into an Insert statement?

Also, what type of field should I use to store this GUID?

9条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-04 11:03

    sys_guid() is a poor option, as other answers have mentioned. One way to generate UUIDs and avoid sequential values is to generate random hex strings yourself:

    select regexp_replace(
        to_char(
            DBMS_RANDOM.value(0, power(2, 128)-1),
            'FM0xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'),
        '([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') from DUAL;
    

提交回复
热议问题