先建立一个sequence:-- Create sequence
create sequence SEQ1
minvalue 0
maxvalue 999999999
start with 0
increment by 1
cycle
order;
然后在插入的时候:insert into t1(userID,user) values(seq1.nextval,'aaa');就可以了,但是userID 用char(1)恐怕有问题吧
create sequence SEQ1
minvalue 0
maxvalue 999999999
start with 0
increment by 1
cycle
order;
然后在插入的时候:insert into t1(userID,user) values(seq1.nextval,'aaa');就可以了,但是userID 用char(1)恐怕有问题吧
你可以试试。
create sequence seq_name
increment by 1
start with 1
maxvalue 99999999
nocycle
cache 10
用触发器
create or replace trigger tri_userid
before insert on table_name
for each row
begin
select seq_name.nextval into :new.userID from dual;
end;
insert into table_name(user) values('aaa');
可以在ORACLE的OEM中建立一个(也可以多个)序列号器
-- Create sequence
create sequence SEQ1
minvalue 0
maxvalue 999999999
start with 0
increment by 1
cycle
order;
-------------
这里的"SEQ1"是序列器的名称,在过程中可以使用的,"increment by 1"表示自动加1,
每次访问这个序列器,返回就会加1nextval 序列的下一个值
currval 序列的当前