我有三张表A,B,C, 
A中有字段a1,a2,a3, 
B中有字段a1,c1, 
C中有字段c1,a2,a3, 
现在想把A中的内容a2,a3通过a1在B表找到与c1对应的关系,然后把输出结果在C表中输出,应该怎么写呢?(B表就起一个连接A表与C表的作用的)希望讲的详细点,谢谢!

解决方案 »

  1.   

    看看是不是对你有启发:
    create or replace procedure my_proc
    is
    begin
      merge into C
      using (select B.c1, A.a2, A.a3 from A, B where A.a1 = B.c1) tmp
      on (C.c1 = tmp.c1 and C.a2 = tmp.a2 and C.a3 = tmp.a3)
      when not matched then
        insert (C.c1, C.a2, C.a3) values (tmp.c1, tmp.a2, tmp.a3);
        
      commit;
      
      exception
        when others then
            rollback;end my_proc;
      

  2.   

     insert into C
     (c1,a2,a3)
     SELECT C.c1,AA.a2,AA.c3
     FROM
     ( select B.c1,A.a2,A.a3 
       from A,B
       where A.a1 = B.a1
     ) AA,
     C
     WHERE AA.C1 = C.C1
      

  3.   

    oracle 9i以后推荐用merge into
      

  4.   

    insert into C(c1,c2,c3) 
    select B.c1, A.a2,A.a3  from A join B on A.a1=B.a1
      

  5.   


    update c set (a2,a3)=(select a.a2,a.a3 from a ,b where a.a1=b.a1 and b.c1=c.c1 and rownum=1 )
      

  6.   

    给你写出查询吧,插入部分自己写SELECT B.C1,A.A2,A.A3
    FROM A ,B 
    WHERE A.A1 = B.A1
      

  7.   

    create or replace procedure test as
    begin
       insert into c 
       select c1,a2,a3
       from a,b
       where a.a1=b.a1;
       commit;
       exception
       when oters then 
       rollback;
       dbms_output.put_line(sqlerrm);
    end;