Oracle 实现主键id自增

第一步:创建表

create table system.rman_db0 (
id int not null,
rman date
);

第二步:创建序列

create sequence system.rman_db0_id
minvalue 1
nomaxvalue
increment by 1
start with 1
nocache;

第三步:创建触发器

create or replace trigger system.rman_db0_tg_insertId
before insert on system.rman_db0 for each row
begin
select system.rman_db0_id.nextval into:new.id from dual;
end;
/

第四步:测试开始 插入两条数据

insert into system.rman_db0(rman) values(systimestamp);
select id, to_char(rman,'yyyy-mm-dd hh24:mi:ss') from system.rman_db0;
点赞

发表回复

电子邮件地址不会被公开。必填项已用 * 标注