How to generate a GUID in Oracle?

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

    Example found on: http://www.orafaq.com/usenet/comp.databases.oracle.server/2006/12/20/0646.htm

    SELECT REGEXP_REPLACE(SYS_GUID(), '(.{8})(.{4})(.{4})(.{4})(.{12})', '\1-\2-\3-\4-\5') MSSQL_GUID  FROM DUAL 
    

    Result:

    6C7C9A50-3514-4E77-E053-B30210AC1082 
    
    0 讨论(0)
  • 2020-12-04 11:27

    You can run the following query

     select sys_guid() from dual
     union all
     select sys_guid() from dual
     union all 
     select sys_guid() from dual
    
    0 讨论(0)
  • 2020-12-04 11:28

    It is not clear what you mean by auto-generate a guid into an insert statement but at a guess, I think you are trying to do something like the following:

    INSERT INTO MY_TAB (ID, NAME) VALUES (SYS_GUID(), 'Adams');
    INSERT INTO MY_TAB (ID, NAME) VALUES (SYS_GUID(), 'Baker');
    

    In that case I believe the ID column should be declared as RAW(16);

    I am doing this off the top of my head. I don't have an Oracle instance handy to test against, but I think that is what you want.

    0 讨论(0)
提交回复
热议问题