1.首先创建一个表
create table users (
id number(2),
username varchar(100),
password varchar(100),
password_salt varchar(100),
constraint pk_users primary key(id)
)
2.创建序列
create sequence seq_users
minvalue 1
nomaxvalue
start with 1
increment by 1
nocycle --一直累加,不循环
nocache; --不缓存
--cache 10; --缓存10条
3.创建触发器
CREATE OR REPLACE TRIGGER tr_tb_user
BEFORE INSERT ON users FOR EACH ROW WHEN (new.id is null)
begin
select seq_tb_user.nextval into:new.id from dual;
end;