一:--循环向表emp中插入数据
1 declare 2 maxnumber number:=10000; 3 v_count number; 4 begin 5 v_count :=0; 6 FOR x IN 1..maxnumber 7 LOOP 8 v_count :=v_count+1; 9 insert into emp (empno,ename,job,mgr,sal,comm) 10 values(1001,‘tom‘,‘clerk‘,1001,1000,120); 11 if mod(v_count,1000) = 0 then 12 commit; 13 end if; 14 END LOOP ; 15 commit; 16 end;
二:--创建与emp表结构相同的临时表
1 create table emp_bak 2 as 3 select * from emp; 4 truncate table emp_bak;
三:--通过存储过程将表emp中的数据同步到临时表emp_bak中
1 create or replace procedure p_syn_data 2 Is 3 v_num number; 4 Begin 5 V_Num :=0; 6 For X In (Select * From Emp) 7 Loop 8 begin 9 V_Num:=V_Num+1; 10 Insert Into Emp (Empno,Ename,Job,Mgr,Sal,Comm) 11 Values(X.Empno,X.Ename,X.Job,X.Mgr,X.Sal,X.Comm); 12 If Mod(V_Num,1000) = 0 Then 13 Commit; 14 End If; 15 end; 16 End Loop; 17 Commit; 18 Dbms_Output.Put_Line("同步数据完成!"); 19 end p_syn_data;
查看临时表数据:
1 --查看临时表数据 2 select count(1) from emp_bak;
时间: 2024-10-27 13:57:24