一. 創(chuàng)建空表
create  table dept_test as select * from scott.dept where rownum >1000;


二. 創(chuàng)建序列
--如果原表已經(jīng)有數(shù)據(jù), 則用max(**id)取得最大id值, 并以該值加1作為基值: start with max(**id)+1
create sequence dept_seq minvalue 1 maxvalue 100 start with 1 increment by 1 nocache; 


三. 創(chuàng)建觸發(fā)器
create or replace trigger dept_trig
  before insert on dept_test for each row
  begin
       select dept_seq.nextval into :new.deptno from dual;
  end;

四. 抽取并插入數(shù)據(jù)
   insert into dept_test(dname) select dname from scott.dept;