Anonymous 发表于 2021-9-15 13:02:57

oracle 自增主键方法





BEGIN
        select XL_ID.nextval into :NEW.ID from dual;
END;select pid.nextval into :new.pid from dual;
第一个pid就是之前序列的名称,改成自己的即可。 第二个pid就是表里需要自增的字段。

使用语法来进行创建
二:使用语句创建

1:创建索引

create sequence SEQ_USERINFO---索引名称
minvalue 1 –最小值
nomaxvalue –不设置最大值
start with 1 –从1开始计数
increment by 1 –每次加1个
nocycle –一直累加,不循环
nocache; –不建缓冲区

2:创建触发器

create or replace trigger tri_person(自定义触发器名称)
before insert
on person----表名
for each row
begin
select seq_person(之前定义的序列名).nextval into :new.pid(需要自增的字段) from dual; end;
例如:

create or replace trigger pid
before insert
on PROCESS_CHECK
for each row
declare
-- local variables here
begin
select PROCESS_CHECK_SEQUENCE.nextval into :new.ID_ from dual;
end ;

页: [1]
查看完整版本: oracle 自增主键方法