How to generate a GUID in Oracle?

前端 未结 9 600
悲哀的现实
悲哀的现实 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:11

    You can use the SYS_GUID() function to generate a GUID in your insert statement:

    insert into mytable (guid_col, data) values (sys_guid(), 'xxx');
    

    The preferred datatype for storing GUIDs is RAW(16).

    As Gopinath answer:

     select sys_guid() from dual
     union all
     select sys_guid() from dual
     union all 
     select sys_guid() from dual
    

    You get

    88FDC68C75DDF955E040449808B55601
    88FDC68C75DEF955E040449808B55601
    88FDC68C75DFF955E040449808B55601

    As Tony Andrews says, differs only at one character

    88FDC68C75DDF955E040449808B55601
    88FDC68C75DEF955E040449808B55601
    88FDC68C75DFF955E040449808B55601

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

提交回复
热议问题