首先创建一张表:
create table ogg.yonghu
(id number generated by default as identity,
name varchar2(60),
CONSTRAINT "PK_USERTAweBLE" PRIMARY KEY ("ID"))
自增主键
generated by default as identity
循环插入数据:
创建存储过程:
declare
i NUMBER;
begin
for i in 1..1000000 loop
insert into ogg.yonghu (name)
values ('SYSDBA');
commit;
end LOOP;
END;
方式二:序列化+显示调用
第一步:创建序列sequence
创建sequence
create sequence seq_ogg_nuo
increment by 1
start with 1
nomaxvalue
nocycle
nocache;
第二步:显示调用序列
insert into ogg.yonghu values('001', 'zhangsan', seq_ogg_nuo.nextval);
第三步:查询进行查看
select * from dept_p
注:
//查看序列当前值和下一个值的查看方式
select seq_ogg_nuo.currval from dual;
select seq_ogg_nuo.nextval from dual;
总结:
create sequence 序列名
[increment by n]
[start with n]
[{maxvalue/minvalue n | nomaxvalue}]
[{cycle|nocycle}]
[{cache n | nocache}];