将表t_uaer的字段ID设置为自增:(用序列sequence的方法来实现)
----创建表
Create table t_user(
Id number(6),userid varchar2(20),loginpassword varchar2(20),isdisable number(6)
);
----创建序列
create sequence user_seq
increment by 1
start with 1
nomaxvalue
nominvalue
nocache
----创建触发器
create or replace trigger tr_user
before insert on t_user
for each row
begin
select user_seq.nextval into :new.id from dual;
end;
----测试
insert into t_user(userid,loginpassword, isdisable)
values('ffll','liudddyujj', 0);
insert into t_user(userid,loginpassword, isdisable)
values('dddd','zhang', 0)
select * from t_user;
就可以看出结果。