How should I store a GUID in Oracle?

后端 未结 7 769
无人及你
无人及你 2020-12-08 02:16

I am coming from the SQL server world where we had uniqueidentifier. Is there an equivalent in oracle? This column will be frequently queried so performance is the key.

相关标签:
7条回答
  • 2020-12-08 02:26
    CREATE table test (testguid RAW(16) default SYS_GUID() ) 
    

    This blog studied the relative performance.

    0 讨论(0)
  • 2020-12-08 02:35

    If I understand the question properly, you want to generate a unique id when you insert a row in the db.
    You could use a sequence to do this. link here
    Once you have created your sequence you can use it like this:

    INSERT INTO mytable (col1, col2) VALUES (myseq.NEXTVAL, 'some other data');
    
    0 讨论(0)
  • 2020-12-08 02:35

    GUIDs are not as used in Oracle as in MSSQL, we tend to have a NUMBER field (not null & primary key) , a sequence, and a trigger on insert to populate it (for every table).

    0 讨论(0)
  • 2020-12-08 02:36

    The general practice using Oracle is to create an artificial key. This is a column defined as a number. It is populated via a sequence. It is indexed/constrained via a primary key definition.

    0 讨论(0)
  • 2020-12-08 02:38

    There is no uniqueidentifier in Oracle.

    You can implement one yourself by using RAW (kind of a pain) or CHAR. Performance on queries that JOIN on a CHAR field will suffer (maybe as much as 40%) in comparison with using an integer.

    If you're doing distributed/replicated databases, the performance hit is worth it. Otherwise, just use an integer.

    0 讨论(0)
  • 2020-12-08 02:41

    RAW(16) is apparently the preferred equivalent for the uniqueidentifier MS SQL type.

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