[size=large]
[http://tech.ccidnet.com/art/1107/20080528/1460789_1.html]
◆1.创建序列
-- Create sequence
create sequence INNERID
minvalue 1
maxvalue 99999999999999
start with 1
increment by 1
cache 20
order;
◆2.--INNERID.currval 指当前序列
--INNERID.nextval 指下一个序列
insert into admin values (INNERID.nextval,'a');
insert into admin values (INNERID.nextval,'b');
insert into admin values (INNERID.nextval,'c');
insert into admin values (INNERID.nextval,'d');
create table admin
(id varchar2(20),name varchar2(10));
--不断的插入序列的下一个值.
◆3.创建触发器(注:此处无法设置id的默认值为INNERID.nextval )
CREATE OR REPLACE TRIGGER admin_tg
--admin id 的触发器
BEFORE INSERT ON admin FOR EACH ROW
BEGIN
SELECT INNERID.NEXTVAL INTO :NEW.id FROM DUAL;
END;
测试语句如下:
insert into admin (username) values ( 'zdz');
成功插入数据,再查看数据,你可以发现id自动增长了,此问题至此解决!
[http://tech.ccidnet.com/art/1107/20080528/1460789_1.html]
◆1.创建序列
-- Create sequence
create sequence INNERID
minvalue 1
maxvalue 99999999999999
start with 1
increment by 1
cache 20
order;
◆2.--INNERID.currval 指当前序列
--INNERID.nextval 指下一个序列
insert into admin values (INNERID.nextval,'a');
insert into admin values (INNERID.nextval,'b');
insert into admin values (INNERID.nextval,'c');
insert into admin values (INNERID.nextval,'d');
create table admin
(id varchar2(20),name varchar2(10));
--不断的插入序列的下一个值.
◆3.创建触发器(注:此处无法设置id的默认值为INNERID.nextval )
CREATE OR REPLACE TRIGGER admin_tg
--admin id 的触发器
BEFORE INSERT ON admin FOR EACH ROW
BEGIN
SELECT INNERID.NEXTVAL INTO :NEW.id FROM DUAL;
END;
测试语句如下:
insert into admin (username) values ( 'zdz');
成功插入数据,再查看数据,你可以发现id自动增长了,此问题至此解决!