How to create id with AUTO_INCREMENT on Oracle?

后端 未结 16 1641
死守一世寂寞
死守一世寂寞 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条回答
  •  南方客
    南方客 (楼主)
    2020-11-21 05:37

    Maybe just try this simple script:

    http://www.hlavaj.sk/ai.php

    Result is:

    CREATE SEQUENCE TABLE_PK_SEQ; 
    CREATE OR REPLACE TRIGGER TR_SEQ_TABLE BEFORE INSERT ON TABLE FOR EACH ROW 
    
    BEGIN
    SELECT TABLE_PK_SEQ.NEXTVAL
    INTO :new.PK
    FROM dual;
    END;
    

提交回复
热议问题