CREATE SEQUENCE emp_sequence -- emp_sequence這個就是後面要用到這個序列號時引用的名稱INCREMENT BY 1 -- 每次加幾個START WITH 1 -- 從1開始計數NOMAXVALUE -- 不設置最大值NOCYCLE -- 一直累加,不循環CACHE 100; -- 緩存值 100
create sequence S_TB_STUDENT
minvalue 1
maxvalue 999999999999999999999999999
start with 1
increment by 1
cache 20;
oracle如何設置序列自動增長
droptable book;
--創建表
createtable book(
bookId varchar2(4) primarykey,
name varchar2(20)
);
--創建序列
createsequence book_seq start with 1 increment by 1;
--創建觸發器
createorreplacetrigger book_trigger
before inserton book
for each row
begin
select book_seq.nextval into :new.bookId from dual;
end ;
--添加數據
insertinto book(name) values ('cc');
insertinto book(name) values ('dd');
commit;
create or replace trigger mytable_trig_autoinc
before insert on mid_org_orgs
for each row
begin
if (:new.mid_id is null) then
select mid_id.nextval into :new.mid_id from dual;
end if;
end;
CHAR(19) default to_char(sysdate,'yyyy-mm-dd hh24:mi:ss'),