我想要把2张结构一样的表,都是有一样约束的。把这2 表合并,还要有效率。怎么弄呢??请教各位高手。。

解决方案 »

  1.   

    重复的算吗? 试试merge into Oracle merge into 的用法详解实例作用:merge into 解决用B表跟新A表数据,如果A表中没有,则把B表的数据插入A表;语法:MERGE INTO [your table-name] [rename your table here]USING ( [write your query here] )[rename your query-sql and using just like a table]ON ([conditional expression here] AND [...]...)WHEN MATHED THEN [here you can execute some update sql or something else ]WHEN NOT MATHED THEN [execute something else here ! ]  -------实例-------
    merge into  a
    using (select id,name from b ) c
    on(a.id=c.id )
    when matched then update set a.name=c.name
    when not matched then insert (a.id,a.name) values (c.id,c.name);
    作用:利用表 b 跟新表a ,条件是a.id=b.id,如果a表中没有该条件的数据就插入。如果你的数据量很大,此sql效率非常高。
      

  2.   

    楼主提问得太笼统
    搜merge into 的用法
      

  3.   

    select a.* from a
    union all
    select b.* from b 
      

  4.   

    insert into test1 select * from test2

    create table test3 as (select * from test1 union all  select * from test2)