4张表:
A表:字段a1,a2,a3,a4,a5
B表:字段a1,a2,a3,b1,b2,b3
C表:字段a1,a2,a3,c1,c2,c3,c4,c5
D表:字段a1,a2,a3,d1,d2,d3
现在需要把4张表中相同的字段a1,a2,a3合并到一个表中
新表中有4个字段,另外一个字段是区分不同表数据的标志(00-A表,01-B表,02-C表,03-D表)在oracle存储过程中使用游标怎么解决?

解决方案 »

  1.   


    insert into newtable(,,,)
    select * from (
      select '00-A表',a1,a2,a3 from a
      union --all
      select '01-B表',a1,a2,a3 from b
      union --all
      select '02-C表',a1,a2,a3 from c
      union --all
      select '03-D表',a1,a2,a3 from d
    )
      

  2.   

    yes
    create table newtab as 
    select a1,a2,a3,'00' flag from a union all
    select a1,a2,a3,'01' from b union all
    ....
      

  3.   


    用union all --不合并重复的记录union --合并重复的记录
      

  4.   

    游标的话
    begin
    for cur1 in (select a1,a2,a3 from a)
    loop
      insert into newtab values(cur1.a1,cur1.a2,cur1.a3,'00');
    end loop;for cur2 in (select a1,a2,a3 from b)
    ....end;
    这个效率比insert into select ..低