Ta      Tb
C1  C2  C1  C3
1   a   1   x
2   b   3   y
怎么实现
C1  C2  C3
1   a   x
2   b
3       y

解决方案 »

  1.   

    SQL> create table ta(c1 number,c2 varchar2(10));Table created.
    SQL> create table tb(c1 number,c3 varchar2(10));Table created.SQL> insert into ta values(1,'a');1 row created.SQL> insert into ta values(2,'b');1 row created.SQL> insert into tb values(1,'x');1 row created.SQL> insert into tb values(3,'y');1 row created.SQL> commit;Commit complete.SQL> select * from ta;        C1 C2
    ---------- ----------
             1 a
             2 bSQL> select * from tb;        C1 C3
    ---------- ----------
             1 x
             3 y
    SQL> select nvl(a.c1,b.c1),a.c2,b.c3
      2  from ta a
      3  full outer join
      4  tb b
      5  on(a.c1=b.c1);NVL(A.C1,B.C1) C2         C3
    -------------- ---------- ----------
                 1 a          x
                 2 b
                 3            y
      

  2.   

    SELECT NVL(A.C1, B.C1), A.C2, B.C3
      FROM TA A
      FULL OUTER JOIN TB B 
      ON A.C1 = B.C1;做全连接就行了!