Oracle 创建自增字段
create table t_users
(
userid number primary key ,
username varchar2(20) not null unique ,
userpwd varchar2(20) not null
);
create sequence seq_users_userid
start with 1
increment by 1;
create trigger tr_users_userid
before
insert
on t_users
for each row
begin
select seq_users_userid.nextval into :new.userid from dual;
end;
insert into t_users (username,userpwd) values ('admin','admin');
insert into t_users (username,userpwd) values('handson','handson');
需要注意的是 :new.userid 中的冒号和new中间不能有空格