How to create id with AUTO_INCREMENT on Oracle?

后端 未结 16 1668
死守一世寂寞
死守一世寂寞 2020-11-21 04:52

It appears that there is no concept of AUTO_INCREMENT in Oracle, up until and including version 11g.

How can I create a column that behaves like auto increment in Or

16条回答
  •  Happy的楠姐
    2020-11-21 05:36

    Trigger and Sequence can be used when you want serialized number that anyone can easily read/remember/understand. But if you don't want to manage ID Column (like emp_id) by this way, and value of this column is not much considerable, you can use SYS_GUID() at Table Creation to get Auto Increment like this.

    CREATE TABLE  
    (emp_id RAW(16) DEFAULT SYS_GUID() PRIMARY KEY,
    name VARCHAR2(30));
    

    Now your emp_id column will accept "globally unique identifier value". you can insert value in table by ignoring emp_id column like this.

    INSERT INTO  (name) VALUES ('name value');
    

    So, it will insert unique value to your emp_id Column.

提交回复
热议问题