CREATE SEQUENCE emp_sequence -- emp_sequence这个就是后面要用到这个序列号时引用的名称
INCREMENT BY 1 -- 每次加几个
START WITH 1 -- 从1开始计数
NOMAXVALUE -- 不设置最大值
NOCYCLE -- 一直累加,不循环
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;
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'),