ORACLE数据库实现id自增

先创建自己需要的表:

create table dept_p(

    dept_id   VARCHAR2(40) not null,
    dept_name VARCHAR2(40),
    dept_sex VARCHAR2(40)
);
alter table DEPT_P add [constraint dept_id] primary key(dept_id);

序列化+触发器:

create sequence seq_t_dept
minvalue 1
maxvalue 99999999
start with 1
increment by 1
cache 50
create or replace trigger "dept_trig"
    before insert on dept_p
    referencing old as old new as new for each row
declare
begin
    select seq_t_dept.nextval into :new.id from dual;
end dept_trig;
//插入数据测试
insert into dept_p(dept_name,dept_sex) values('安保部', '');
select * from dept_p;
原文地址:https://www.cnblogs.com/zmh-980509/p/13912803.html