创建表 create table LoginUser ( Pid number(6) primary key, username varchar(20) not null, userpwd varchar(20) not null, usertype varchar(12) not null ); 创建序列 create sequence LoginUser_seq increment by 1 start with 1 nomaxvalue nominvalue nocache 创建触发器其中一定要注意new.pid这个地方 create or replace trigger tr_user before insert on loginuser for each row begin select LoginUser_seq.nextval into :new.pid from dual; end; 执行sql插入语句 insert into LoginUser(username,Userpwd,Usertype) values('jack','123','管理员'); insert into LoginUser(username,Userpwd,Usertype) values('jney','123','普通用户'); 查看执行结果 select * from loginuser