问答详情
源自:3-4 Oracle管理表

字段自增长

oracle数据库id怎么实现自增长

提问者:qq_爱深埋于心i_0 2017-03-01 16:23

个回答

  • 慕勒0069038
    2017-03-01 17:29:29

    create table Test_Table
    (
    ID number(11) primary key,
    Name varchar(50) not null
    )


    create sequence AutoID
    start with 1 //根据需要自己可修改该数值
    increment by 1 //步长值
    minvalue 1
    nomaxvalue



    create trigger AutoID_Trigger

    before insert on Test_Table for each row
    begin
    select AutoID.nextval into :new.ID from dual;
    end AutoID_Trigger;