索引
--1、插入tsm_employee 表100万数据
--(1.1)、为雇员编码创建一个序列s_emp_no
create sequence s_emp_no
start with 1000000
increment by 1
minvalue 1
maxvalue 2000000
nocycle
cache 10;
--(1.2)、在tsm_department 加入一条数据,部门编码为 test
insert into tsm_department(dept_no,dept_name, create_date)
values('test','test',sysdate);
commit;
--(1.3)、插入100万数据
set time on;
set serveroutput on;
declare
insert_num integer := 1000000;
insert_num_per integer := 1;
begin
for i in 1 .. insert_num loop
insert into tsm_employee
(emp_no, name, position, dept_no)
values
(s_emp_no.nextval, 'test' || s_emp_no.currval, 'test', 'test');
if insert_num_per = 200 then
insert_num_per := 1; --
commit;
end if;
insert_num_per := insert_num_per + 1;
end loop;
commit; --如果最后没到200要提交
exception
when others then
rollback; --出现异常要回滚
dbms_output.put_line(substr(sqlerrm, 1, 200));
end;