◆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自動增長了,此問題至此解決!