日期:2014-05-17  浏览次数:20971 次

ORACLE多表合并
我有两张表分别为TABLE1(a,b,c) TABLE2 (e,f) 怎么样把这两表合并成一张表table3(a,b,c,e,f)

------解决方案--------------------
create table t3 as select a,b,c,e,f from t1,t2 where ... and rownum <= 1;

truncate t3;

SQL code
create or replace procedure proc 
is
   type t_cur is ref cursor;
   insert_cur t_cur;
   type t_rec is table of t3%rowtype index by binary_integer;
   rows_rec t_rec;
begin
   open insert_cur for select a,b,c,e,f from t1,t2 where ...;
   loop
      fetch insert_cur bulk collect into rows_rec
      limit 1000;
      exit when insert_cur%notfound;
      forall i in rows_rec.first..rows_rec.last
         insert into t3 values rows_rec(i);
      commit;
   end loop;
end proc;

------解决方案--------------------
探讨
create table t3 as select a,b,c,e,f from t1,t2 where ... and rownum <= 1;

truncate t3;

SQL codecreateorreplaceprocedureprocis
type t_curis refcursor;
insert_cur t_cur;
type t_recistableof t3%rowtypeindexby binary_integer;
rows_rec t_rec;beginopen insert_curforselect a,b,c,e,ffrom t1,t2where ...;
loopfetch insert_curbulk collectinto rows_rec
limit1000;exitwhen insert_cur%notfound;
forall iin rows_rec.first..rows_rec.lastinsertinto t3values rows_rec(i);commit;end loop;endproc;